﻿using System;
using System.Collections.Generic;
//using System.Linq;
using System.Text;
using CrystalDecisions.CrystalReports.Engine;
using System.Data;
using LPV_POS.In;
using LPV_POS;
using LPV_POS.Module;
using LPV_POS.Baocao;
using LPV_POS.Baocao.Epson;
using LPV_POS.Baocao.Bixolon;
using System.Windows.Forms;
using LPV_POS.thuvien_cls;
using LPV_POS.mh_pos;
using System.Globalization;
using System.Resources;


class Mod_baocaodoanhthu_hienhanh_in
{
    CultureInfo culture;
    string str_lang = ""; 
    cpublic ocpublic = new cpublic();
    DataTable tb;
    int i1, i2, i3;   // = 56
    string Print_Align_Left = ((char)(27)).ToString() + ((char)(97)).ToString() + '\0';

    #region "   f_splitString4Column"
    string f_splitString4Column(string a, string b, string c, string d, int i1, int i2, int i3)
    {//i1: 32; i2:7; i3: 17
        string str = "";
        cpublic ocpublic = new cpublic();
        a = ocpublic.RemoveSign4VietnameseString(a).Trim();
        str = a;
        str += ocpublic.Spacestring(i1 - a.Length - b.Length);
        str += b;
        str += ocpublic.Spacestring(i2 - c.Length);
        str += c;
        str += ocpublic.Spacestring(i3 - d.Length);
        str += d;
        return str;
    }
    #endregion

    #region "   f_splitString3Column"
    string f_splitString3Column(string a, string b, string c, int i1, int i2)
    {//i1: 29; i2:13
        cpublic ocpublic = new cpublic();
        string str = "";
        a = ocpublic.RemoveSign4VietnameseString(a).Trim();
        str = a;
        str += ocpublic.Spacestring(i1 - a.Length - b.Length);
        str += b;
        str += ocpublic.Spacestring(i2 - c.Length);
        str += c;
        return str;
    }
    #endregion

    #region "   f_splitString3Column"
    string f_splitString2Column(string a, string b)
    {//i1: 29; i2:13
        int i1 = 42;
        cpublic ocpublic = new cpublic();
        string str = "";
        a = ocpublic.RemoveSign4VietnameseString(a).Trim();
        str = a;
        str += ocpublic.Spacestring(i1 - a.Length - b.Length);
        str += b;
        return str;
    }
    #endregion

    public void f_baocaodoanhthu_hienhanh_in(string loaibaocao, DataSet _dsbaocao, DataTable dt_bcthe) // bc httt, editor: PL, date: 2012.07.25
    {
        
        //if (i == tb.Rows.Count / 2)
        
        culture = CultureInfo.CurrentCulture;
        cpublic ocpublic = new cpublic();
        str_lang = ocpublic.Registry_Get("mh_main_lang");
        if (str_lang == "")
            str_lang = "vi-VN";
        culture = CultureInfo.CreateSpecificCulture(str_lang);
        ResourceManager rm = new ResourceManager("LPV_POS.Muti_language.MyResource", typeof(mh_banhang6_PhuThu).Assembly);
        //ocpublic = new cpublic();
        ReportDocument rpt;
        thuvien tv = new thuvien();
        DataTable tbBN = tv.SP_SelectDataTable("sp_DM_MAYIN_BIENNHAN", null, null);
        
        DataView dv = tbBN.DefaultView;
        dv.Sort = "COMNAME";
        int vitri = dv.Find(new object[] { "USB" });
        int vitri_bixolon = dv.Find(new object[] { "BIXOLON" });
        int vitri_bixolon_100 = dv.Find(new object[] { "BIXOLON100" });
        
        string tencongty = "";
        string dienthoai = "";
        string diachi = "";
        
        Mod_header_report header_report = new Mod_header_report();
        
        tb = header_report.f_selectheaderreport();
        
        if (tb.Rows.Count > 0)
        {
            tencongty = tb.Rows[0]["HEADER"] + "";
            dienthoai = tb.Rows[0]["PHONE"] + "";
            diachi = tb.Rows[0]["ADDRESS"] + "";
        }
        
        // Khởi tao class in bill 2:
        PrintCOMs oPrintCOMs = new PrintCOMs(PrintCOMs.Print_Type.Print_BILL);
        SerialPort_LPV[] aSerialPort_LPV = oPrintCOMs.Print_Start();
        
        switch (loaibaocao)
        {
            case "nhomchu":
                #region "   "

                if (_dsbaocao.Tables[0].Rows.Count > 0 && (_dsbaocao.Tables[0].Rows[0]["THANHTIENTRUOC"] + "") != "")
                {
                    if (vitri > -1 || vitri_bixolon > -1 || vitri_bixolon_100 > -1)
                    {

                        #region "bao cao ban tieng viet"
                        if (vitri > -1)
                            rpt = new bc_nhomchu_in_VN();
                        else
                            rpt = new bc_nhomchu_in_Bixolon();

                        CrystalDecisions.CrystalReports.Engine.TextObject str_tencongty;
                        str_tencongty = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_tencongty"];
                        str_tencongty.Text = tencongty;

                        CrystalDecisions.CrystalReports.Engine.TextObject str_dienthoai;
                        str_dienthoai = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_dienthoaicongty"];
                        str_dienthoai.Text = dienthoai;

                        CrystalDecisions.CrystalReports.Engine.TextObject str_diachi;
                        str_diachi = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_diachicongty"];
                        str_diachi.Text = diachi;           //txt_ngaythangnam

                        CrystalDecisions.CrystalReports.Engine.TextObject str_baocaongay;
                        str_baocaongay = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_tungaydenngay"];
                        str_baocaongay.Text = Variable.str_tungay;           //txt_ngaythangnam


                        CrystalDecisions.CrystalReports.Engine.TextObject str_ngayinbill;
                        str_ngayinbill = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_ngaythangnam"];
                        str_ngayinbill.Text = rm.GetString("ngay", culture) + " " + string.Format("{0:dd/MM/yyyy}", DateTime.Today);           //txt_ngaythangnam
                        //-----------------------------------------------
                        
                        CrystalDecisions.CrystalReports.Engine.TextObject str_bill;
                        str_bill = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_baocaodoanhthu"];
                        str_bill.Text = rm.GetString("doanhthunhomchu", culture);

                        str_bill = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["Text2"];
                        str_bill.Text = rm.GetString("stt_bill", culture);

                        str_bill = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["Text3"];
                        str_bill.Text = rm.GetString("nhomchu", culture);

                        str_bill = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["Text4"];
                        str_bill.Text = rm.GetString("thanhtien_bill", culture);

                        str_bill = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["Text6"];
                        str_bill.Text = rm.GetString("tienmat_bill", culture);

                        rpt.SetDataSource(_dsbaocao.Tables[1]);
                        rpt.DataDefinition.FormulaFields["NHOMCHU"].Text = "{dt_report.NHOMCHU}" + "";
                        rpt.DataDefinition.FormulaFields["THANHTIEN"].Text = "{dt_report.THANHTIENTRUOC}" + "";
                        rpt.DataDefinition.FormulaFields["TIENMAT"].Text = "{dt_report.TIENMAT}" + "";


                        #region "   PrinterDefault"
                        System.Drawing.Printing.PrinterSettings cls = new System.Drawing.Printing.PrinterSettings();
                        string sPrinterDefault = cls.PrinterName;
                        if (sPrinterDefault != "")
                            rpt.PrintOptions.PrinterName = sPrinterDefault;


                        try
                        {
                            if (ocpublic.Registry_Get("chkCrystalReport_Display") + "" == "True")
                            {
                                mh_View frm = new mh_View(rpt);
                                frm.Show();
                            }
                        }
                        catch (Exception ex)
                        {
                        }
                        #endregion
                        
                        rpt.PrintToPrinter(1, true, 1, 100);
                        rpt.Dispose();//-----Xóa file tmp rpt---07/07/2012
                        #endregion
                        
                    }
                    else
                    {
                        #region "bao cao may in ellic"

                        string nhomchu = "";
                        string thanhtien = "";
                        string tienmat = "";
                        string tyle = "";
                        foreach (SerialPort_LPV oSerialPort_LPV in aSerialPort_LPV)
                        {
                            if (oSerialPort_LPV != null)
                            {
                                //=======================================HEADER===============================================================================
                                oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Double_Height, "BAO CAO DOANH THU NHOM CHU", "", "", "");
                                oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, Variable.str_tungay, "", "", "");

                                oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, ' ', PrintCOMs.Fills.Fills_Full);

                                if (tencongty != "")
                                    oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, tencongty, "", "", "");
                                if (dienthoai != "")
                                    oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, dienthoai, "", "", "");
                                if (diachi != "")
                                    oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, diachi, "", "", "");

                                oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, '=', PrintCOMs.Fills.Fills_Full);
                                //==================================================DETAIL====================================================================

                                oSerialPort_LPV.Write(Print_Align_Left);
                                i1 = 29;
                                i2 = 13;
                                //i3 = 10;   // = 56
                                oSerialPort_LPV.WriteLine(this.f_splitString3Column("Nhom chu", "Thanh tien", "Tien mat", i1, i2));
                                oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, '-', PrintCOMs.Fills.Fills_Full);

                                //========================================================
                                //lay dataset cua doanh thu theo nhom chu

                                tb = _dsbaocao.Tables[1];
                                ocpublic = new cpublic();
                                for (int i = 0; i < tb.Rows.Count; i++)
                                {
                                    nhomchu = ocpublic.RemoveSign4VietnameseString(tb.Rows[i]["NHOMCHU"] + "");
                                    thanhtien = (decimal.Parse(tb.Rows[i]["THANHTIENTRUOC"] + "")).ToString("N0");
                                    tienmat = (decimal.Parse(tb.Rows[i]["TIENMAT"] + "")).ToString("N0");
                                    tyle = tb.Rows[i]["TYLE"] + "";

                                    string nhomchu_2 = "";
                                    #region "   nhomchu_2"
                                    if (nhomchu.Length + thanhtien.Length >= i1)
                                    {
                                        int iSpace = 0;
                                        int icount = 0;
                                        while (icount + thanhtien.Length < i1)
                                        {
                                            if (nhomchu.IndexOf(' ', icount) == icount)
                                                iSpace = icount;
                                            icount++;
                                        }
                                        string sTmp = "";

                                        sTmp = nhomchu.Substring(0, iSpace).Trim();
                                        nhomchu_2 = nhomchu.Substring(iSpace).Trim();
                                        nhomchu = sTmp;

                                    }

                                    #endregion
                                    oSerialPort_LPV.WriteLine(this.f_splitString3Column(nhomchu, thanhtien, tienmat, i1, i2));
                                    if (nhomchu_2 != "")
                                        oSerialPort_LPV.WriteLine(this.f_splitString3Column(nhomchu_2, "", "", i1, i2));


                                    if (i != tb.Rows.Count - 1)
                                        oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, '-', PrintCOMs.Fills.Fills_Full);
                                }

                                //=======================================FOOTER===============================================================================
                                oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, '=', PrintCOMs.Fills.Fills_Full);
                                oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, "Ngày in bill " + DateTime.Today.ToString("dd/MM/yyyy"), "", "", "");
                                oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, ' ', PrintCOMs.Fills.Fills_Full);

                                oPrintCOMs.Print_Bottom(oSerialPort_LPV);

                            }
                        }
                        #endregion
                    }
                }
                else
                {
                    Mod_messagebox mess = new Mod_messagebox();
                    mess.messagebox_pos("Thông báo", "Chưa có doanh thu", loaithongbao.canhbao.GetHashCode());
                    return;
                }
                break;
                #endregion
            case "nhomhang":
                #region "   "
                if (_dsbaocao.Tables[0].Rows.Count > 0 && (_dsbaocao.Tables[0].Rows[0]["THANHTIENTRUOC"] + "") != "")
                {
                    //int vitri_bixolon_100 = dv.Find(new object[] { "BIXOLON100" });
                    if (vitri > -1 || vitri_bixolon > -1 || vitri_bixolon_100 > -1)
                    {
                        #region "bao cao ban tieng viet"

                        // bc_nhomhang_in_VN rpt = new bc_nhomhang_in_VN();
                        if (vitri > -1)
                            rpt = new bc_nhomhang_in_VN();
                        else
                            rpt = new bc_nhomhang_in_Bixolon();
                        CrystalDecisions.CrystalReports.Engine.TextObject str_tencongty;
                        str_tencongty = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_tencongty"];
                        str_tencongty.Text = tencongty;

                        CrystalDecisions.CrystalReports.Engine.TextObject str_dienthoai;
                        str_dienthoai = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_dienthoaicongty"];
                        str_dienthoai.Text = dienthoai;

                        CrystalDecisions.CrystalReports.Engine.TextObject str_diachi;
                        str_diachi = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_diachicongty"];
                        str_diachi.Text = diachi;           //txt_ngaythangnam

                        CrystalDecisions.CrystalReports.Engine.TextObject str_baocaongay;
                        str_baocaongay = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_tungaydenngay"];
                        str_baocaongay.Text = Variable.str_tungay;           //txt_ngaythangnam


                        CrystalDecisions.CrystalReports.Engine.TextObject str_ngayinbill;
                        str_ngayinbill = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_ngaythangnam"];
                        str_ngayinbill.Text = rm.GetString("ngay", culture) + " " + string.Format("{0:dd/MM/yyyy}", DateTime.Today);           //txt_ngaythangnam
                        //------------------------------------------------------
                        CrystalDecisions.CrystalReports.Engine.TextObject str_nhomhangbill;
                        str_nhomhangbill = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_baocaodoanhthu"];
                        str_nhomhangbill.Text = rm.GetString("txt_baocaodoanhthu", culture);

                        str_nhomhangbill = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["Text1"];
                        str_nhomhangbill.Text = rm.GetString("stt_bill", culture);

                        str_nhomhangbill = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["Text2"];
                        str_nhomhangbill.Text = rm.GetString("nhomhang", culture);

                        str_nhomhangbill = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["Text4"];
                        str_nhomhangbill.Text = rm.GetString("thanhtien_bill", culture);

                        str_nhomhangbill = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["Text6"];
                        str_nhomhangbill.Text = rm.GetString("tienmat_bill", culture); 

                        rpt.SetDataSource(_dsbaocao.Tables[1]);
                        rpt.DataDefinition.FormulaFields["NHOMHANG"].Text = "{dt_report.NHOMHANG}" + "";
                        rpt.DataDefinition.FormulaFields["THANHTIEN"].Text = "{dt_report.THANHTIENTRUOC}" + "";
                        rpt.DataDefinition.FormulaFields["TIENMAT"].Text = "{dt_report.TIENMAT}" + "";

                        #region "   PrinterDefault"
                        System.Drawing.Printing.PrinterSettings cls = new System.Drawing.Printing.PrinterSettings();
                        string sPrinterDefault = cls.PrinterName;
                        rpt.PrintOptions.PrinterName = sPrinterDefault;
                        #endregion

                        try
                        {
                            if (ocpublic.Registry_Get("chkCrystalReport_Display") + "" == "True")
                            {
                                mh_View frm = new mh_View(rpt);
                                frm.Show();
                            }
                        }
                        catch (Exception ex)
                        {
                        }
                        rpt.PrintToPrinter(1, true, 1, 100);
                        rpt.Dispose();//-----Xóa file tmp rpt---07/07/2012
                        #endregion
                    }
                    else
                    {
                        #region "bao cao may in ellic"

                        string nhomhang = "";
                        string thanhtien = "";
                        string tienmat = "";
                        string tyle = "";
                        foreach (SerialPort_LPV oSerialPort_LPV in aSerialPort_LPV)
                        {
                            if (oSerialPort_LPV != null)
                            {
                                //=======================================HEADER===============================================================================
                                oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Double_Height, "BAO CAO DOANH THU NHOM HANG", "", "", "");
                                oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, Variable.str_tungay, "", "", "");

                                oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, ' ', PrintCOMs.Fills.Fills_Full);

                                if (tencongty != "")
                                    oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, tencongty, "", "", "");
                                if (dienthoai != "")
                                    oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, dienthoai, "", "", "");
                                if (diachi != "")
                                    oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, diachi, "", "", "");

                                oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, '=', PrintCOMs.Fills.Fills_Full);
                                //==================================================DETAIL====================================================================

                                oSerialPort_LPV.Write(Print_Align_Left);
                                i1 = 29;
                                i2 = 13;
                                oSerialPort_LPV.WriteLine(this.f_splitString3Column("Nhom hang", "Thanh tien", "Tien mat", i1, i2));

                                oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, '-', PrintCOMs.Fills.Fills_Full);

                                //========================================================
                                //lay dataset cua doanh thu theo nhom chu

                                tb = _dsbaocao.Tables[1];
                                for (int i = 0; i < tb.Rows.Count; i++)
                                {
                                    ocpublic = new cpublic();
                                    nhomhang = ocpublic.RemoveSign4VietnameseString(tb.Rows[i]["NHOMHANG"] + "");
                                    thanhtien = (decimal.Parse(tb.Rows[i]["THANHTIENTRUOC"] + "")).ToString("N0") + "";
                                    tienmat = (decimal.Parse(tb.Rows[i]["TIENMAT"] + "")).ToString("N0") + "";
                                    tyle = tb.Rows[i]["TYLE"] + "";

                                    string nhomhang_2 = "";
                                    #region "   nhomhang_2"
                                    if (nhomhang.Length + thanhtien.Length >= i1)
                                    {
                                        int iSpace = 0;
                                        int icount = 0;
                                        while (icount + thanhtien.Length < i1)
                                        {
                                            if (nhomhang.IndexOf(' ', icount) == icount)
                                                iSpace = icount;
                                            icount++;
                                        }
                                        string sTmp = "";

                                        sTmp = nhomhang.Substring(0, iSpace).Trim();
                                        nhomhang_2 = nhomhang.Substring(iSpace).Trim();
                                        nhomhang = sTmp;

                                    }

                                    #endregion

                                    oSerialPort_LPV.WriteLine(this.f_splitString3Column(nhomhang, thanhtien, tienmat, i1, i2));
                                    if (nhomhang_2 != "")
                                        oSerialPort_LPV.WriteLine(this.f_splitString3Column(nhomhang_2, "", "", i1, i2));

                                    if (i != tb.Rows.Count - 1)
                                        oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, '-', PrintCOMs.Fills.Fills_Full);
                                }

                                //=======================================FOOTER===============================================================================
                                oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, '=', PrintCOMs.Fills.Fills_Full);
                                oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, "Ngày in bill " + DateTime.Today.ToString("dd/MM/yyyy"), "", "", "");
                                oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, ' ', PrintCOMs.Fills.Fills_Full);

                                oPrintCOMs.Print_Bottom(oSerialPort_LPV);

                            }
                        }
                        #endregion
                    }
                }
                else
                {
                    Mod_messagebox mess = new Mod_messagebox();
                    mess.messagebox_pos("Thông báo", "Chưa có doanh thu", loaithongbao.canhbao.GetHashCode());
                    return;
                }
                break;
                #endregion
            case "mathang":
                #region "   "
                if (_dsbaocao.Tables[0].Rows.Count > 0 && (_dsbaocao.Tables[0].Rows[0]["THANHTIENTRUOC"] + "") != "")
                {

                    //int vitri_bixolon_100 = dv.Find(new object[] { "BIXOLON100" });
                    if (vitri > -1 || vitri_bixolon > -1 || vitri_bixolon_100 > -1)
                    {
                        #region "bao cao ban tieng viet"

                        //bc_hanghoa_in_VN rpt = new bc_hanghoa_in_VN();
                        if (vitri > -1)
                            rpt = new bc_hanghoa_in_VN();
                        else
                            rpt = new bc_hanghoa_in_Bixolon();
                        // bc_hanghoa_in_Bixolon rpt = new bc_hanghoa_in_Bixolon();

                        CrystalDecisions.CrystalReports.Engine.TextObject str_tencongty;
                        str_tencongty = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_tencongty"];
                        str_tencongty.Text = tencongty;

                        CrystalDecisions.CrystalReports.Engine.TextObject str_dienthoai;
                        str_dienthoai = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_dienthoaicongty"];
                        str_dienthoai.Text = dienthoai;

                        CrystalDecisions.CrystalReports.Engine.TextObject str_diachi;
                        str_diachi = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_diachicongty"];
                        str_diachi.Text = diachi;           //txt_ngaythangnam

                        CrystalDecisions.CrystalReports.Engine.TextObject str_baocaongay;
                        str_baocaongay = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_tungaydenngay"];
                        str_baocaongay.Text = Variable.str_tungay;           //txt_ngaythangnam


                        CrystalDecisions.CrystalReports.Engine.TextObject str_doanhthumathang;
                        str_doanhthumathang = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_baocaodoanhthu"];
                        str_doanhthumathang.Text = rm.GetString("doanhthumathang", culture);       


                        CrystalDecisions.CrystalReports.Engine.TextObject str_ngayinbill;
                        str_ngayinbill = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_ngaythangnam"];
                        str_ngayinbill.Text = rm.GetString("ngay", culture) + " " +string.Format("{0:dd/MM/yyyy}", DateTime.Today);           //txt_ngaythangnam
                        
                        //------------------------------------------------------
                        CrystalDecisions.CrystalReports.Engine.TextObject str_mathang;
                        str_mathang = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["Text3"];
                        str_mathang.Text = rm.GetString("mon", culture);

                        CrystalDecisions.CrystalReports.Engine.TextObject str_stt;
                        str_stt = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["Text2"];
                        str_stt.Text = rm.GetString("stt_bill", culture);  
                        
                        CrystalDecisions.CrystalReports.Engine.TextObject str_soluong;

                        str_soluong  = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["Text1"];
                        str_soluong.Text = rm.GetString("soluong_bill", culture);

                        CrystalDecisions.CrystalReports.Engine.TextObject str_thanhtien;
                        str_thanhtien = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["Text4"];
                        str_thanhtien.Text = rm.GetString("thanhtien_bill", culture);

                        CrystalDecisions.CrystalReports.Engine.TextObject str_tongtien;
                        str_tongtien = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["Text6"];
                        str_tongtien.Text = rm.GetString("tienmat_bill", culture); 

                        rpt.SetDataSource(_dsbaocao.Tables[1]);
                        rpt.DataDefinition.FormulaFields["TENHH"].Text = "{dt_report.HANGHOA}" + "";
                        rpt.DataDefinition.FormulaFields["THANHTIEN"].Text = "{dt_report.THANHTIENTRUOC}" + "";
                        rpt.DataDefinition.FormulaFields["SOLUONG"].Text = "{dt_report.SOLUONG}" + "";
                        rpt.DataDefinition.FormulaFields["TIENMAT"].Text = "{dt_report.TIENMAT}" + "";

                        #region "   PrinterDefault"
                        System.Drawing.Printing.PrinterSettings cls = new System.Drawing.Printing.PrinterSettings();
                        string sPrinterDefault = cls.PrinterName;
                        rpt.PrintOptions.PrinterName = sPrinterDefault;
                        #endregion
                        try
                        {
                            if (ocpublic.Registry_Get("chkCrystalReport_Display") + "" == "True")
                            {
                                mh_View frm = new mh_View(rpt);
                                frm.Show();
                            }
                        }
                        catch (Exception ex)
                        {
                        }
                        rpt.PrintToPrinter(1, true, 1, 100);
                        rpt.Dispose();//-----Xóa file tmp rpt---07/07/2012
                        #endregion
                    }
                    else
                    {
                        #region "bao cao may in ellic"

                        string mathang = "";
                        string soluong = "";
                        string tienmat = "";
                        string tyle = "";
                        foreach (SerialPort_LPV oSerialPort_LPV in aSerialPort_LPV)
                        {
                            if (oSerialPort_LPV != null)
                            {
                                //=======================================HEADER===============================================================================
                                oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Double_Height, "BAO CAO DOANH THU MAT HANG", "", "", "");
                                oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, Variable.str_tungay, "", "", "");

                                oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, ' ', PrintCOMs.Fills.Fills_Full);

                                if (tencongty != "")
                                    oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, tencongty, "", "", "");
                                if (dienthoai != "")
                                    oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, dienthoai, "", "", "");
                                if (diachi != "")
                                    oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, diachi, "", "", "");

                                oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, '=', PrintCOMs.Fills.Fills_Full);
                                //==================================================DETAIL====================================================================
                                //oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, "Stt", "Mat hang", "T tien", "Ch lech", "Tien mat", "Ty le");
                                oSerialPort_LPV.Write(Print_Align_Left);
                                i1 = 29;
                                i2 = 13;
                                oSerialPort_LPV.WriteLine(this.f_splitString3Column("Mat hang", "S luong", "Tien mat", i1, i2));
                                //oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, "Mat hang", "S luong  ",  "Tien mat", "Ty le");
                                oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, '-', PrintCOMs.Fills.Fills_Full);

                                //========================================================
                                //lay dataset cua doanh thu theo nhom chu

                                tb = _dsbaocao.Tables[1];
                                for (int i = 0; i < tb.Rows.Count; i++)
                                {
                                    if (tb.Rows[i]["HANGHOA"] + "" == "")
                                    {
                                        oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, '-', PrintCOMs.Fills.Fills_Full);
                                        continue;
                                    }
                                    ocpublic = new cpublic();
                                    mathang = ocpublic.RemoveSign4VietnameseString(tb.Rows[i]["HANGHOA"] + "");

                                    soluong = (decimal.Parse(tb.Rows[i]["SOLUONG"] + "")).ToString("N0") + "";
                                    tienmat = (decimal.Parse(tb.Rows[i]["TIENMAT"] + "")).ToString("N0") + "";
                                    tyle = tb.Rows[i]["TYLE"] + "";

                                    string mathang_2 = "";
                                    #region "   sTenHang2"
                                    if (mathang.Length + soluong.Length >= i1)
                                    {
                                        int iSpace = 0;
                                        int icount = 0;
                                        while (icount + soluong.Length < i1)
                                        {
                                            if (mathang.IndexOf(' ', icount) == icount)
                                                iSpace = icount;
                                            icount++;
                                        }
                                        string sTmp = "";

                                        sTmp = mathang.Substring(0, iSpace).Trim();
                                        mathang_2 = mathang.Substring(iSpace).Trim();
                                        mathang = sTmp;

                                    }

                                    #endregion


                                    oSerialPort_LPV.WriteLine(this.f_splitString3Column(mathang, soluong, tienmat, i1, i2));
                                    if (mathang_2 != "")
                                        oSerialPort_LPV.WriteLine(this.f_splitString3Column(mathang_2, "", "", i1, i2));

                                }

                                //=======================================FOOTER===============================================================================
                                oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, '=', PrintCOMs.Fills.Fills_Full);
                                oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, "Ngày in bill " + DateTime.Today.ToString("dd/MM/yyyy"), "", "", "");
                                oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, ' ', PrintCOMs.Fills.Fills_Full);

                                oPrintCOMs.Print_Bottom(oSerialPort_LPV);

                            }
                        }
                        #endregion
                    }

                }
                else
                {
                    Mod_messagebox mess = new Mod_messagebox();
                    mess.messagebox_pos("Thông báo", "Chưa có doanh thu", loaithongbao.canhbao.GetHashCode());
                    return;
                }
                break;
                #endregion
            case "baocaotheogio":   //======================== BAO CAO THEO GIO
                #region "   "
                foreach (SerialPort_LPV oSerialPort_LPV in aSerialPort_LPV)
                {
                    if (oSerialPort_LPV != null)
                    {
                        string thoigian = "";
                        string ban = "";
                        string khachhang = "";
                        string banhang = "";
                        //=======================================HEADER===============================================================================
                        oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Double_Height, "BAO CAO DOANH THU THEO GIO", "", "", "");
                        oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, Variable.str_tungay, "", "", "");

                        oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, ' ', PrintCOMs.Fills.Fills_Full);

                        if (tencongty != "")
                            oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, tencongty, "", "", "");
                        if (dienthoai != "")
                            oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, dienthoai, "", "", "");
                        if (diachi != "")
                            oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, diachi, "", "", "");

                        oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, '=', PrintCOMs.Fills.Fills_Full);
                        //==================================================DETAIL====================================================================
                        oSerialPort_LPV.Write(Print_Align_Left);
                        i1 = 20;
                        i2 = 12;
                        i3 = 10;   // = 56
                        oSerialPort_LPV.WriteLine(this.f_splitString4Column("Thoi gian", "Ban", "Khach hang", "Ban hang", i1, i2, i3));

                        oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, '-', PrintCOMs.Fills.Fills_Full);

                        //========================================================
                        //lay dataset cua doanh thu theo nhom chu

                        tb = _dsbaocao.Tables[1];
                        for (int i = 0; i < tb.Rows.Count; i++)
                        {

                            if (tb.Rows[i]["THANHTIEN"] + "" != "0")
                            {
                                thoigian = tb.Rows[i]["thoi_gian"] + "";
                                ban = (decimal.Parse(tb.Rows[i]["ban"] + "").ToString("N0")) + "";
                                khachhang = (decimal.Parse(tb.Rows[i]["khachhang"] + "")).ToString("N0") + "";
                                banhang = (decimal.Parse(tb.Rows[i]["THANHTIEN"] + "")).ToString("N0");

                                oSerialPort_LPV.WriteLine(this.f_splitString4Column(thoigian, ban, khachhang, banhang, i1, i2, i3));

                                if (i != tb.Rows.Count - 1)
                                    oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, '-', PrintCOMs.Fills.Fills_Full);
                            }
                        }

                        //=======================================FOOTER===============================================================================
                        oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, '=', PrintCOMs.Fills.Fills_Full);
                        oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, "Ngày in bill " + DateTime.Today.ToString("dd/MM/yyyy"), "", "", "");
                        oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, ' ', PrintCOMs.Fills.Fills_Full);

                        oPrintCOMs.Print_Bottom(oSerialPort_LPV);

                    }
                }

                break;
                #endregion
            case "nv_tongquat":
                #region "   "
                if (_dsbaocao.Tables[0].Rows.Count > 0)
                {
                    //int vitri_bixolon_100 = dv.Find(new object[] { "BIXOLON100" });
                    if (vitri > -1 || vitri_bixolon > -1 || vitri_bixolon_100 > -1)
                    {
                        #region "bao cao ban tieng viet"

                        //bc_nhanvientongquat_in_VN rpt = new bc_nhanvientongquat_in_VN();
                        if (vitri > -1)
                            rpt = new bc_nhanvientongquat_in_VN();
                        else
                            rpt = new bc_nhanvientongquat_in_Bixolon();

                        CrystalDecisions.CrystalReports.Engine.TextObject str_tencongty;
                        str_tencongty = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_tencongty"];
                        str_tencongty.Text = tencongty;

                        CrystalDecisions.CrystalReports.Engine.TextObject str_dienthoai;
                        str_dienthoai = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_dienthoaicongty"];
                        str_dienthoai.Text = dienthoai;

                        CrystalDecisions.CrystalReports.Engine.TextObject str_diachi;
                        str_diachi = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_diachicongty"];
                        str_diachi.Text = diachi;           //txt_ngaythangnam

                        CrystalDecisions.CrystalReports.Engine.TextObject str_baocaongay;
                        str_baocaongay = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_tungaydenngay"];
                        str_baocaongay.Text = Variable.str_tungay;           //txt_ngaythangnam
                        //--------------------------------------------------
                        CrystalDecisions.CrystalReports.Engine.TextObject str_nhanvien;
                        str_nhanvien = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["Text2"];
                        str_nhanvien.Text = rm.GetString("stt_bill", culture);

                        str_nhanvien = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["Text1"];
                        str_nhanvien.Text = rm.GetString("ten", culture);

                        str_nhanvien = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["Text7"];
                        str_nhanvien.Text = rm.GetString("tienmat_bill", culture);

                        str_nhanvien = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["Text6"];
                        str_nhanvien.Text = rm.GetString("giamgia_bill", culture);

                        CrystalDecisions.CrystalReports.Engine.TextObject str_ngayinbill;
                        str_ngayinbill = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_ngaythangnam"];
                        str_ngayinbill.Text = rm.GetString("ngay", culture) + " " +string.Format("{0:dd/MM/yyyy}", DateTime.Today);           //txt_ngaythangnam

                        rpt.SetDataSource(_dsbaocao.Tables[0]);
                        rpt.DataDefinition.FormulaFields["TEN"].Text = "{dt_report.TEN}" + "";
                        rpt.DataDefinition.FormulaFields["TONG_CONG"].Text = "{dt_report.TONG_CONG}" + "";
                        rpt.DataDefinition.FormulaFields["DC"].Text = "{dt_report.DC}" + "";

                        #region "   PrinterDefault"
                        System.Drawing.Printing.PrinterSettings cls = new System.Drawing.Printing.PrinterSettings();
                        string sPrinterDefault = cls.PrinterName;
                        rpt.PrintOptions.PrinterName = sPrinterDefault;
                        #endregion
                        try
                        {
                            if (ocpublic.Registry_Get("chkCrystalReport_Display") + "" == "True")
                            {
                                mh_View frm = new mh_View(rpt);
                                frm.Show();
                            }
                        }
                        catch (Exception ex)
                        {
                        }
                        rpt.PrintToPrinter(1, true, 1, 100);
                        rpt.Dispose();//-----Xóa file tmp rpt---07/07/2012
                        #endregion
                    }
                    else
                    {
                        #region "bao cao may in ellic"

                        ocpublic = new cpublic();
                        foreach (SerialPort_LPV oSerialPort_LPV in aSerialPort_LPV)
                        {
                            if (oSerialPort_LPV != null)
                            {
                                //=======================================HEADER===============================================================================
                                oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Double_Height, "BAO CAO NHAN VIEN TONG QUAT", "", "", "");
                                oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, Variable.str_tungay, "", "", "");

                                oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, ' ', PrintCOMs.Fills.Fills_Full);

                                if (tencongty != "")
                                    oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, tencongty, "", "", "");
                                if (dienthoai != "")
                                    oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, dienthoai, "", "", "");
                                if (diachi != "")
                                    oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, diachi, "", "", "");

                                oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, '=', PrintCOMs.Fills.Fills_Full);
                                //==================================================DETAIL====================================================================
                                // oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, "Ten", "Vao", "", "Ra", "", "Trong khoang");


                                //========================================================
                                //lay dataset cua doanh thu theo nhom chu
                                oSerialPort_LPV.Write(Print_Align_Left);
                                i1 = 20;
                                i2 = 10;
                                i3 = 12;   // = 56
                                tb = _dsbaocao.Tables[0];
                                for (int i = 0; i < tb.Rows.Count; i++)
                                {

                                    string ten = ocpublic.RemoveSign4VietnameseString(tb.Rows[i]["TEN"] + "");
                                    string Luotvaogannhat = tb.Rows[i]["LUOT_VAO_GAN_NHAT"] + "";
                                    if (Luotvaogannhat != "")
                                        Luotvaogannhat = (DateTime.Parse(Luotvaogannhat)).ToString("dd/MM/yyyy hh:mm:ss");

                                    string Luotragannhat = tb.Rows[i]["LUOT_RA_GAN_NHAT"] + "";
                                    if (Luotragannhat != "")
                                        Luotragannhat = (DateTime.Parse(Luotragannhat)).ToString("dd/MM/yyyy hh:mm:ss");

                                    string Luotbanhangdautien = tb.Rows[i]["LUOT_BAN_HANG_DAU_TIEN"] + "";
                                    if (Luotbanhangdautien != "")
                                        Luotbanhangdautien = (DateTime.Parse(Luotbanhangdautien)).ToString("dd/MM/yyyy hh:mm:ss");

                                    string Luotbanhangcuoicung = tb.Rows[i]["LUOT_BAN_HANG_CUOI_CUNG"] + "";
                                    if (Luotbanhangcuoicung != "")
                                        Luotbanhangcuoicung = (DateTime.Parse(Luotbanhangcuoicung)).ToString("dd/MM/yyyy hh:mm:ss");

                                    string DC = tb.Rows[i]["DC"] + "";
                                    if (DC != "")
                                        DC = decimal.Parse(DC).ToString("N0");


                                    oSerialPort_LPV.WriteLine(this.f_splitString4Column("Ten", "", "", ten, i1, i2, i3));
                                    oSerialPort_LPV.WriteLine(this.f_splitString4Column("Luot vao gan nhat", " ", "", Luotvaogannhat, i1, i2, i3));
                                    oSerialPort_LPV.WriteLine(this.f_splitString4Column("Luot ra gan nhat", " ", "", Luotragannhat, i1, i2, i3));
                                    oSerialPort_LPV.WriteLine(this.f_splitString4Column("Luot ban hang dau tien", "", "", Luotbanhangdautien, i1, i2, i3));
                                    oSerialPort_LPV.WriteLine(this.f_splitString4Column("Luot ban hang cuoi cung", "", "", Luotbanhangcuoicung, i1, i2, i3));
                                    oSerialPort_LPV.WriteLine(this.f_splitString4Column("DC", "", "", DC, i1, i2, i3));

                                }

                                //=======================================FOOTER===============================================================================
                                oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, '=', PrintCOMs.Fills.Fills_Full);
                                oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, "In bao cao ngay " + DateTime.Today.ToString("dd/MM/yyyy"), "", "", "");
                                oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, ' ', PrintCOMs.Fills.Fills_Full);

                                oPrintCOMs.Print_Bottom(oSerialPort_LPV);

                            }
                        }
                        #endregion
                    }

                }
                else
                {
                    Mod_messagebox mess = new Mod_messagebox();
                    mess.messagebox_pos("Thông báo", "Chưa có doanh thu", loaithongbao.canhbao.GetHashCode());
                    return;
                }

                break;
                #endregion
            case "nv_chitietvaora":
                #region "   "
                if (_dsbaocao.Tables[0].Rows.Count > 0)
                {
                    //int vitri_bixolon_100 = dv.Find(new object[] { "BIXOLON100" });
                    if (vitri > -1 || vitri_bixolon > -1 || vitri_bixolon_100 > -1)
                    {
                        #region "bao cao ban tieng viet"

                        // bc_nhanvien_chitietvaora_in_VN rpt = new bc_nhanvien_chitietvaora_in_VN();
                        if (vitri > -1)
                            rpt = new bc_nhanvien_chitietvaora_in_VN();
                        else
                            rpt = new bc_nhanvien_chitietvaora_in_Bixolon();

                        CrystalDecisions.CrystalReports.Engine.TextObject str_tencongty;
                        str_tencongty = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_tencongty"];
                        str_tencongty.Text = tencongty;

                        CrystalDecisions.CrystalReports.Engine.TextObject str_dienthoai;
                        str_dienthoai = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_dienthoaicongty"];
                        str_dienthoai.Text = dienthoai;

                        CrystalDecisions.CrystalReports.Engine.TextObject str_diachi;
                        str_diachi = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_diachicongty"];
                        str_diachi.Text = diachi;           //txt_ngaythangnam

                        CrystalDecisions.CrystalReports.Engine.TextObject str_baocaongay;
                        str_baocaongay = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_tungaydenngay"];
                        str_baocaongay.Text = Variable.str_tungay;           //txt_ngaythangnam


                        CrystalDecisions.CrystalReports.Engine.TextObject str_ngayinbill;
                        str_ngayinbill = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_ngaythangnam"];
                        str_ngayinbill.Text = rm.GetString("ngay", culture) + " " + string.Format("{0:dd/MM/yyyy}", DateTime.Today);           //txt_ngaythangnam
                        //-------------------------------------------------------
                        CrystalDecisions.CrystalReports.Engine.TextObject str_nhanvien_vaora;
                        str_nhanvien_vaora = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["Text1"];
                        str_nhanvien_vaora.Text = rm.GetString("ten", culture);

                        str_nhanvien_vaora = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["Text2"];
                        str_nhanvien_vaora.Text = rm.GetString("vaoca", culture);

                        str_nhanvien_vaora = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["Text3"];
                        str_nhanvien_vaora.Text = rm.GetString("raca", culture);

                        str_nhanvien_vaora = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["Text4"];
                        str_nhanvien_vaora.Text = rm.GetString("trongkhoang", culture);


                        rpt.SetDataSource(_dsbaocao.Tables[0]);
                        rpt.DataDefinition.FormulaFields["TEN"].Text = "{dt_report.TEN}" + "";
                        rpt.DataDefinition.FormulaFields["VAO"].Text = "{dt_report.VAO}" + "";
                        rpt.DataDefinition.FormulaFields["RA"].Text = "{dt_report.RA}" + "";
                        rpt.DataDefinition.FormulaFields["TRONG_KHOANG"].Text = "{dt_report.TRONG_KHOANG}" + "";

                        #region "   PrinterDefault"
                        System.Drawing.Printing.PrinterSettings cls = new System.Drawing.Printing.PrinterSettings();
                        string sPrinterDefault = cls.PrinterName;
                        rpt.PrintOptions.PrinterName = sPrinterDefault;
                        #endregion
                        try
                        {
                            if (ocpublic.Registry_Get("chkCrystalReport_Display") + "" == "True")
                            {
                                mh_View frm = new mh_View(rpt);
                                frm.Show();
                            }
                        }
                        catch (Exception ex)
                        {
                        }
                        rpt.PrintToPrinter(1, true, 1, 100);
                        rpt.Dispose();//-----Xóa file tmp rpt---07/07/2012
                        #endregion
                    }
                    else
                    {
                        #region "bao cao may in ellic"
                        foreach (SerialPort_LPV oSerialPort_LPV in aSerialPort_LPV)
                        {
                            if (oSerialPort_LPV != null)
                            {
                                //=======================================HEADER===============================================================================
                                oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Double_Height, "BAO CAO NHAN VIEN CHI TIET VAO RA", "", "", "");
                                oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, Variable.str_tungay, "", "", "");

                                oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, ' ', PrintCOMs.Fills.Fills_Full);

                                if (tencongty != "")
                                    oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, tencongty, "", "", "");
                                if (dienthoai != "")
                                    oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, dienthoai, "", "", "");
                                if (diachi != "")
                                    oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, diachi, "", "", "");

                                oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, '=', PrintCOMs.Fills.Fills_Full);
                                //==================================================DETAIL====================================================================
                                //oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, "Ten", "Vao",  "Ra",  "Trong khoang");
                                //oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, '-', PrintCOMs.Fills.Fills_Full);

                                //========================================================
                                //lay dataset cua doanh thu theo nhom chu
                                string ten = "";
                                tb = _dsbaocao.Tables[0];
                                for (int i = 0; i < tb.Rows.Count; i++)
                                {
                                    if (tb.Rows[i]["COLOR"] + "" == "2")
                                        ten = "Tong cong";
                                    else
                                        ten = tb.Rows[i]["TEN"] + "";
                                    string vao = tb.Rows[i]["VAO"] + "";
                                    if (vao != "")
                                        vao = (DateTime.Parse(vao)).ToString("dd/MM/yyyy hh:mm:ss");
                                    string ra = tb.Rows[i]["RA"] + "";
                                    if (ra != "")
                                        ra = (DateTime.Parse(ra)).ToString("dd/MM/yyyy hh:mm:ss");
                                    string trongkhoang = tb.Rows[i]["TRONG_KHOANG"] + "";

                                    oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, "Ten", "", ten, "");
                                    oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, "Vao ca", "", vao, "");
                                    oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, "Ra ca", "", ra, "");
                                    oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, "Trong khoang", "", trongkhoang, "");


                                    if (i != tb.Rows.Count - 1)
                                        oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, '-', PrintCOMs.Fills.Fills_Full);
                                }

                                //=======================================FOOTER===============================================================================
                                oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, '=', PrintCOMs.Fills.Fills_Full);
                                oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, "In bill ngay " + DateTime.Today.ToString("dd/MM/yyyy"), "", "", "");
                                oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, ' ', PrintCOMs.Fills.Fills_Full);

                                oPrintCOMs.Print_Bottom(oSerialPort_LPV);

                            }
                        }
                        #endregion
                    }

                }
                else
                {
                    Mod_messagebox mess = new Mod_messagebox();
                    mess.messagebox_pos("Thông báo", "Chưa có doanh thu", loaithongbao.canhbao.GetHashCode());
                    return;
                }

                break;
                #endregion
            case "nv_chitiet":
                #region "   "
                if (_dsbaocao.Tables[0].Rows.Count > 0)
                {
                    //int vitri_bixolon_100 = dv.Find(new object[] { "BIXOLON100" });
                    if (vitri > -1 || vitri_bixolon > -1 || vitri_bixolon_100 > -1)
                    {
                        #region "bao cao ban tieng viet"

                        //  bc_nhanvien_chitiet_in_VN rpt = new bc_nhanvien_chitiet_in_VN();
                        if (vitri > -1)
                            rpt = new bc_nhanvien_chitiet_in_VN();
                        else
                            rpt = new bc_nhanvien_chitiet_in_Bixolon();

                        CrystalDecisions.CrystalReports.Engine.TextObject str_tencongty;
                        str_tencongty = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_tencongty"];
                        str_tencongty.Text = tencongty;

                        CrystalDecisions.CrystalReports.Engine.TextObject str_dienthoai;
                        str_dienthoai = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_dienthoaicongty"];
                        str_dienthoai.Text = dienthoai;

                        CrystalDecisions.CrystalReports.Engine.TextObject str_diachi;
                        str_diachi = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_diachicongty"];
                        str_diachi.Text = diachi;           //txt_ngaythangnam

                        CrystalDecisions.CrystalReports.Engine.TextObject str_baocaongay;
                        str_baocaongay = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_tungaydenngay"];
                        str_baocaongay.Text = Variable.str_tungay;           //txt_ngaythangnam


                        CrystalDecisions.CrystalReports.Engine.TextObject str_ngayinbill;
                        str_ngayinbill = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_ngaythangnam"];
                        str_ngayinbill.Text = rm.GetString("ngay", culture) + " " + string.Format("{0:dd/MM/yyyy}", DateTime.Today);           //txt_ngaythangnam
                        //-------------------------------------------------------------------
                        CrystalDecisions.CrystalReports.Engine.TextObject str_nhanvienchitiet;
                        str_nhanvienchitiet = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["Text1"];
                        str_nhanvienchitiet.Text = rm.GetString("ngay", culture);

                        str_nhanvienchitiet = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["Text7"];
                        str_nhanvienchitiet.Text = rm.GetString("the", culture);

                        str_nhanvienchitiet = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["Text2"];
                        str_nhanvienchitiet.Text = rm.GetString("thanhtien_bill", culture);

                        str_nhanvienchitiet = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["Text3"];
                        str_nhanvienchitiet.Text = rm.GetString("tienmat_bill", culture);

                        str_nhanvienchitiet = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["Text5"];
                        str_nhanvienchitiet.Text = rm.GetString("giamgia_bill", culture);


                        rpt.SetDataSource(_dsbaocao.Tables[0]);
                        rpt.DataDefinition.FormulaFields["NGAY_HE_THONG"].Text = "{dt_report.NGAY_HE_THONG}" + "";
                        rpt.DataDefinition.FormulaFields["SO"].Text = "{dt_report.SO}" + "";
                        rpt.DataDefinition.FormulaFields["TONG_CONG"].Text = "{dt_report.TONG_CONG}" + "";
                        rpt.DataDefinition.FormulaFields["TIEN_MAT"].Text = "{dt_report.TIEN_MAT}" + "";
                        rpt.DataDefinition.FormulaFields["THE"].Text = "{dt_report.THE}" + "";
                        rpt.DataDefinition.FormulaFields["DC"].Text = "{dt_report.DC}" + "";

                        #region "   PrinterDefault"
                        System.Drawing.Printing.PrinterSettings cls = new System.Drawing.Printing.PrinterSettings();
                        string sPrinterDefault = cls.PrinterName;
                        rpt.PrintOptions.PrinterName = sPrinterDefault;
                        #endregion
                        try
                        {
                            if (ocpublic.Registry_Get("chkCrystalReport_Display") + "" == "True")
                            {
                                mh_View frm = new mh_View(rpt);
                                frm.Show();
                            }
                        }
                        catch (Exception ex)
                        {
                        }
                        rpt.PrintToPrinter(1, true, 1, 100);
                        rpt.Dispose();//-----Xóa file tmp rpt---07/07/2012
                        #endregion
                    }
                    else
                    {
                        #region "bao cao may in ellic"

                        ocpublic = new cpublic();
                        string ngay = "";
                        string sophieu = "";
                        string tienmat = "";
                        string theKH = "";
                        foreach (SerialPort_LPV oSerialPort_LPV in aSerialPort_LPV)
                        {
                            if (oSerialPort_LPV != null)
                            {
                                //=======================================HEADER===============================================================================
                                oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Double_Height, "BAO CAO DOANH THU NHAN VIEN _ CHI TIET", "", "", "");
                                oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, Variable.str_tungay, "", "", "");

                                oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, ' ', PrintCOMs.Fills.Fills_Full);

                                if (tencongty != "")
                                    oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, tencongty, "", "", "");
                                if (dienthoai != "")
                                    oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, dienthoai, "", "", "");
                                if (diachi != "")
                                    oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, diachi, "", "", "");

                                oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, '=', PrintCOMs.Fills.Fills_Full);
                                //==================================================DETAIL====================================================================

                                oSerialPort_LPV.Write(Print_Align_Left);
                                i1 = 20;
                                i2 = 12;
                                i3 = 10;   // = 56
                                oSerialPort_LPV.WriteLine(this.f_splitString4Column("Ngay", "So phieu", "Tien mat", "The KH", i1, i2, i3));

                                oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, '-', PrintCOMs.Fills.Fills_Full);

                                //========================================================
                                //lay dataset cua doanh thu theo nhom chu

                                tb = _dsbaocao.Tables[0];
                                ocpublic = new cpublic();
                                for (int i = 0; i < tb.Rows.Count; i++)
                                {

                                    ngay = ocpublic.RemoveSign4VietnameseString(tb.Rows[i]["NGAY_HE_THONG"] + "");
                                    sophieu = tb.Rows[i]["SO"] + "";
                                    tienmat = tb.Rows[i]["TIEN_MAT"] + "";
                                    if (tienmat != "")
                                        tienmat = decimal.Parse(tienmat).ToString("N0");
                                    theKH = tb.Rows[i]["THE"] + "";

                                    oSerialPort_LPV.WriteLine(this.f_splitString4Column(ngay, sophieu, tienmat, theKH, i1, i2, i3));

                                }

                                //=======================================FOOTER===============================================================================
                                oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, '=', PrintCOMs.Fills.Fills_Full);
                                oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, "Ngay in bill " + DateTime.Today.ToString("dd/MM/yyyy"), "", "", "");
                                oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, ' ', PrintCOMs.Fills.Fills_Full);

                                oPrintCOMs.Print_Bottom(oSerialPort_LPV);

                            }
                        }
                        #endregion
                    }
                }
                else
                {
                    Mod_messagebox mess = new Mod_messagebox();
                    mess.messagebox_pos("Thông báo", "Chưa có doanh thu", loaithongbao.canhbao.GetHashCode());
                    return;
                }

                break;
                #endregion
            case "nv_chitietmathang":
                #region "   "
                if (_dsbaocao.Tables[0].Rows.Count > 0)
                {
                    //int vitri_bixolon_100 = dv.Find(new object[] { "BIXOLON100" });
                    if (vitri > -1 || vitri_bixolon > -1 || vitri_bixolon_100 > -1)
                    {
                        #region "bao cao ban tieng viet"

                        // bc_nhanvien_chitietmathang_in_VN rpt = new bc_nhanvien_chitietmathang_in_VN();
                        if (vitri > -1)
                            rpt = new bc_nhanvien_chitietmathang_in_VN();
                        else
                            rpt = new bc_nhanvien_chitietmathang_in_Bixolon();

                        CrystalDecisions.CrystalReports.Engine.TextObject str_tencongty;
                        str_tencongty = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_tencongty"];
                        str_tencongty.Text = tencongty;

                        CrystalDecisions.CrystalReports.Engine.TextObject str_dienthoai;
                        str_dienthoai = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_dienthoaicongty"];
                        str_dienthoai.Text = dienthoai;

                        CrystalDecisions.CrystalReports.Engine.TextObject str_diachi;
                        str_diachi = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_diachicongty"];
                        str_diachi.Text = diachi;           //txt_ngaythangnam

                        CrystalDecisions.CrystalReports.Engine.TextObject str_baocaongay;
                        str_baocaongay = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_tungaydenngay"];
                        str_baocaongay.Text = Variable.str_tungay;           //txt_ngaythangnam


                        CrystalDecisions.CrystalReports.Engine.TextObject str_ngayinbill;
                        str_ngayinbill = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_ngaythangnam"];
                        str_ngayinbill.Text = rm.GetString("ngay", culture) + " " + string.Format("{0:dd/MM/yyyy}", DateTime.Today);           //txt_ngaythangnam
                        //-----------------------------------------------------------
                        CrystalDecisions.CrystalReports.Engine.TextObject str_nhanvien_CTMH;
                        str_nhanvien_CTMH = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["Text1"];
                        str_nhanvien_CTMH.Text = rm.GetString("mon", culture);

                        str_nhanvien_CTMH = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["Text3"];
                        str_nhanvien_CTMH.Text = rm.GetString("sum", culture);

                        str_nhanvien_CTMH = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["Text4"];
                        str_nhanvien_CTMH.Text = rm.GetString("giamgia_bill", culture);

                        //str_nhanvien_CTMH = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["Text5"];
                        //str_nhanvien_CTMH.Text = rm.GetString("banhang", culture);

                        rpt.SetDataSource(_dsbaocao.Tables[0]);
                        rpt.DataDefinition.FormulaFields["SAN_PHAM"].Text = "{dt_report.SAN_PHAM}" + "";
                        rpt.DataDefinition.FormulaFields["SL"].Text = "{dt_report.SL}" + "";
                        rpt.DataDefinition.FormulaFields["CONG"].Text = "{dt_report.CONG}" + "";
                        rpt.DataDefinition.FormulaFields["DC"].Text = "{dt_report.DC}" + "";
                        rpt.DataDefinition.FormulaFields["SALES"].Text = "{dt_report.SALES}" + "";

                        #region "   PrinterDefault"
                        System.Drawing.Printing.PrinterSettings cls = new System.Drawing.Printing.PrinterSettings();
                        string sPrinterDefault = cls.PrinterName;
                        rpt.PrintOptions.PrinterName = sPrinterDefault;
                        #endregion
                        try
                        {
                            if (ocpublic.Registry_Get("chkCrystalReport_Display") + "" == "True")
                            {
                                mh_View frm = new mh_View(rpt);
                                frm.Show();
                            }
                        }
                        catch (Exception ex)
                        {
                        }
                        rpt.PrintToPrinter(1, true, 1, 100);
                        rpt.Dispose();//-----Xóa file tmp rpt---07/07/2012
                        #endregion
                    }
                    else
                    {
                        #region "bao cao may in ellic"
                        foreach (SerialPort_LPV oSerialPort_LPV in aSerialPort_LPV)
                        {

                            //1111
                            string sanpham = "";
                            string cong = "";
                            string dc = "";
                            string banhang = "";

                            if (oSerialPort_LPV != null)
                            {
                                //=======================================HEADER===============================================================================
                                oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Double_Height, "BAO CAO DOANH THU NHAN VIEN _ MAT HANG", "", "", "");
                                oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, Variable.str_tungay, "", "", "");

                                oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, ' ', PrintCOMs.Fills.Fills_Full);

                                if (tencongty != "")
                                    oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, tencongty, "", "", "");
                                if (dienthoai != "")
                                    oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, dienthoai, "", "", "");
                                if (diachi != "")
                                    oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, diachi, "", "", "");

                                oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, '=', PrintCOMs.Fills.Fills_Full);
                                //==================================================DETAIL====================================================================

                                oSerialPort_LPV.Write(Print_Align_Left);
                                i1 = 20;
                                i2 = 11;
                                i3 = 11;   // = 56
                                oSerialPort_LPV.WriteLine(this.f_splitString4Column("San pham", "Cong", "DC", "Ban hang", i1, i2, i3));
                                // oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, "San pham",  "Cong", "DC", "Ban hang");
                                oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, '-', PrintCOMs.Fills.Fills_Full);

                                //========================================================


                                tb = _dsbaocao.Tables[0];
                                for (int i = 0; i < tb.Rows.Count; i++)
                                {


                                    if (tb.Rows[i]["CONG"] + "" == "")
                                    {
                                        oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, '-', PrintCOMs.Fills.Fills_Full);
                                        oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, ' ', PrintCOMs.Fills.Fills_Full);
                                        continue;
                                    }
                                    ocpublic = new cpublic();
                                    sanpham = ocpublic.RemoveSign4VietnameseString(tb.Rows[i]["SAN_PHAM"] + "");
                                    cong = (decimal.Parse(tb.Rows[i]["CONG"] + "")).ToString("N0");
                                    dc = (decimal.Parse(tb.Rows[i]["DC"] + "")).ToString("N0");
                                    banhang = (decimal.Parse(tb.Rows[i]["SALES"] + "")).ToString("N0");

                                    string sanpham_2 = "";
                                    #region "   sanpham_2"
                                    if (sanpham.Length + cong.Length >= i1)
                                    {
                                        int iSpace = 0;
                                        int icount = 0;
                                        while (icount + cong.Length < i1)
                                        {
                                            if (sanpham.IndexOf(' ', icount) == icount)
                                                iSpace = icount;
                                            icount++;
                                        }
                                        string sTmp = "";

                                        sTmp = sanpham.Substring(0, iSpace).Trim();
                                        sanpham_2 = sanpham.Substring(iSpace).Trim();
                                        sanpham = sTmp;

                                    }

                                    #endregion

                                    oSerialPort_LPV.WriteLine(this.f_splitString4Column(sanpham, cong, dc, banhang, i1, i2, i3));

                                    if (sanpham_2 != "")
                                        oSerialPort_LPV.WriteLine(this.f_splitString4Column(sanpham_2, "", "", "", i1, i2, i3));

                                }

                                //=======================================FOOTER===============================================================================
                                oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, '=', PrintCOMs.Fills.Fills_Full);
                                oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, "Ngay in bill " + DateTime.Today.ToString("dd/MM/yyyy"), "", "", "");
                                oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, ' ', PrintCOMs.Fills.Fills_Full);

                                oPrintCOMs.Print_Bottom(oSerialPort_LPV);

                            }
                        }
                        #endregion
                    }
                }
                else
                {
                    Mod_messagebox mess = new Mod_messagebox();
                    mess.messagebox_pos("Thông báo", "Chưa có doanh thu", loaithongbao.canhbao.GetHashCode());
                    return;
                }
                break;
                #endregion
            case "khuvuc":
                #region "   "
                if (_dsbaocao.Tables[0].Rows.Count > 0 && (_dsbaocao.Tables[0].Rows[0]["THANHTIENTRUOC"] + "") != "")
                {
                    //int vitri_bixolon_100 = dv.Find(new object[] { "BIXOLON100" });
                    if (vitri > -1 || vitri_bixolon > -1 || vitri_bixolon_100 > -1)
                    {
                        #region "bao cao ban tieng viet"

                        // bc_khuvuc_in_VN rpt = new bc_khuvuc_in_VN();
                        if (vitri > -1)
                            rpt = new bc_khuvuc_in_VN();
                        else
                            rpt = new bc_khuvuc_in_Bixolon();

                        CrystalDecisions.CrystalReports.Engine.TextObject str_tencongty;
                        str_tencongty = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_tencongty"];
                        str_tencongty.Text = tencongty;

                        CrystalDecisions.CrystalReports.Engine.TextObject str_dienthoai;
                        str_dienthoai = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_dienthoaicongty"];
                        str_dienthoai.Text = dienthoai;

                        CrystalDecisions.CrystalReports.Engine.TextObject str_diachi;
                        str_diachi = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_diachicongty"];
                        str_diachi.Text = diachi;           //txt_ngaythangnam

                        CrystalDecisions.CrystalReports.Engine.TextObject str_baocaongay;
                        str_baocaongay = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_tungaydenngay"];
                        str_baocaongay.Text = Variable.str_tungay;           //txt_ngaythangnam


                        CrystalDecisions.CrystalReports.Engine.TextObject str_ngayinbill;
                        str_ngayinbill = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_ngaythangnam"];
                        str_ngayinbill.Text = rm.GetString("ngay", culture) + " " + string.Format("{0:dd/MM/yyyy}", DateTime.Today);           //txt_ngaythangnam
                        //------------------------------------------------------
                        CrystalDecisions.CrystalReports.Engine.TextObject str_khuvuc;
                        str_khuvuc = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["Text2"];
                        str_khuvuc.Text = rm.GetString("stt_bill", culture);

                        str_khuvuc = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["Text1"];
                        str_khuvuc.Text = rm.GetString("khuvuc", culture);

                        str_khuvuc = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["Text4"];
                        str_khuvuc.Text = rm.GetString("thanhtien_bill", culture);

                        str_khuvuc = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["Text6"];
                        str_khuvuc.Text = rm.GetString("tienmat_bill", culture);


                        rpt.SetDataSource(_dsbaocao.Tables[1]);
                        rpt.DataDefinition.FormulaFields["KHUVUC"].Text = "{dt_report.TENBAN}" + "";
                        rpt.DataDefinition.FormulaFields["THANHTIEN"].Text = "{dt_report.THANHTIENTRUOC}" + "";
                        //  rpt.DataDefinition.FormulaFields["CHENHLECH"].Text = "{dt_report.CHENHLECH}" + "";
                        rpt.DataDefinition.FormulaFields["TIENMAT"].Text = "{dt_report.TIENMAT}" + "";

                        #region "   PrinterDefault"
                        System.Drawing.Printing.PrinterSettings cls = new System.Drawing.Printing.PrinterSettings();
                        string sPrinterDefault = cls.PrinterName;
                        rpt.PrintOptions.PrinterName = sPrinterDefault;
                        #endregion
                        try
                        {
                            if (ocpublic.Registry_Get("chkCrystalReport_Display") + "" == "True")
                            {
                                mh_View frm = new mh_View(rpt);
                                frm.Show();
                            }
                        }
                        catch (Exception ex)
                        {
                        }
                        rpt.PrintToPrinter(1, true, 1, 100);
                        rpt.Dispose();//-----Xóa file tmp rpt---07/07/2012
                        #endregion
                    }
                    else
                    {
                        #region "bao cao may in ellic"

                        string khuvuc = "";
                        string thanhtien = "";
                        string chenhlech = "";
                        string tienmat = "";

                        foreach (SerialPort_LPV oSerialPort_LPV in aSerialPort_LPV)
                        {
                            if (oSerialPort_LPV != null)
                            {
                                //=======================================HEADER===============================================================================
                                oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Double_Height, "BAO CAO DOANH THU KHU VUC", "", "", "");
                                oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, Variable.str_tungay, "", "", "");

                                oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, ' ', PrintCOMs.Fills.Fills_Full);

                                if (tencongty != "")
                                    oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, tencongty, "", "", "");
                                if (dienthoai != "")
                                    oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, dienthoai, "", "", "");
                                if (diachi != "")
                                    oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, diachi, "", "", "");

                                oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, '=', PrintCOMs.Fills.Fills_Full);

                                //==================================================DETAIL====================================================================
                                oSerialPort_LPV.Write(Print_Align_Left);
                                i1 = 20;
                                i2 = 10;
                                i3 = 12;   // = 56
                                oSerialPort_LPV.WriteLine(this.f_splitString4Column("Ban", "T tien", " Chenh lech", "Tien mat", i1, i2, i3-1));

                                oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, '-', PrintCOMs.Fills.Fills_Full);

                                //========================================================
                                //lay dataset cua doanh thu theo nhom chu

                                tb = _dsbaocao.Tables[1];
                                for (int i = 0; i < tb.Rows.Count; i++)
                                {

                                    if (tb.Rows[i]["THANHTIENTRUOC"] + "" == "")
                                    {
                                        oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, '-', PrintCOMs.Fills.Fills_Full);
                                        continue;
                                    }

                                    ocpublic = new cpublic();
                                    khuvuc = ocpublic.RemoveSign4VietnameseString(tb.Rows[i]["TENBAN"] + "");
                                    thanhtien = (decimal.Parse(tb.Rows[i]["THANHTIENTRUOC"] + "")).ToString("N0") + "";
                                    chenhlech = (decimal.Parse(tb.Rows[i]["CHENHLECH"] + "")).ToString("N0");
                                    tienmat = (decimal.Parse(tb.Rows[i]["TIENMAT"] + "")).ToString("N0");


                                    string khuvuc_2 = "";
                                    #region "   khuvuc_2"
                                    if (khuvuc.Length + thanhtien.Length >= i1)
                                    {
                                        int iSpace = 0;
                                        int icount = 0;
                                        while (icount + thanhtien.Length < i1)
                                        {
                                            if (khuvuc.IndexOf(' ', icount) == icount)
                                                iSpace = icount;
                                            icount++;
                                        }
                                        string sTmp = "";

                                        sTmp = khuvuc.Substring(0, iSpace).Trim();
                                        khuvuc_2 = khuvuc.Substring(iSpace).Trim();
                                        khuvuc = sTmp;

                                    }

                                    #endregion
                                    oSerialPort_LPV.WriteLine(this.f_splitString4Column(khuvuc, thanhtien, chenhlech, tienmat, i1, i2, i3));
                                    if (khuvuc_2 != "")
                                        oSerialPort_LPV.WriteLine(this.f_splitString4Column(khuvuc_2, "", "", "", i1, i2, i3));


                                    if (i != tb.Rows.Count - 1)
                                        oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, '-', PrintCOMs.Fills.Fills_Full);
                                }

                                //=======================================FOOTER===============================================================================
                                oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, '=', PrintCOMs.Fills.Fills_Full);
                                oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, "In bill ngay " + DateTime.Today.ToString("dd/MM/yyyy"), "", "", "");
                                oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, ' ', PrintCOMs.Fills.Fills_Full);

                                oPrintCOMs.Print_Bottom(oSerialPort_LPV);

                            }
                        }
                        #endregion
                    }

                }
                else
                {
                    Mod_messagebox mess = new Mod_messagebox();
                    mess.messagebox_pos("Thông báo", "Chưa có doanh thu", loaithongbao.canhbao.GetHashCode());
                    return;
                }

                break;
                #endregion
            case "ban":
            case "khuvuc_ct":
                #region "   "
                if (_dsbaocao.Tables[0].Rows.Count > 0 && (_dsbaocao.Tables[0].Rows[0]["THANHTIENTRUOC"] + "") != "")
                {
                    if (vitri > -1 || vitri_bixolon > -1 || vitri_bixolon_100 > -1)
                    {
                        #region "bao cao ban tieng viet"

                        //bc_ban_in_VN rpt = new bc_ban_in_VN();
                        if (vitri > -1)
                            rpt = new bc_ban_in_VN();
                        else
                            rpt = new bc_ban_in_Bixolon();

                        //bc_ban_in_Bixolon rpt = new bc_ban_in_Bixolon();

                        CrystalDecisions.CrystalReports.Engine.TextObject str_tencongty;
                        str_tencongty = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_tencongty"];
                        str_tencongty.Text = tencongty;

                        CrystalDecisions.CrystalReports.Engine.TextObject str_dienthoai;
                        str_dienthoai = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_dienthoaicongty"];
                        str_dienthoai.Text = dienthoai;

                        CrystalDecisions.CrystalReports.Engine.TextObject str_diachi;
                        str_diachi = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_diachicongty"];
                        str_diachi.Text = diachi;           //txt_ngaythangnam

                        CrystalDecisions.CrystalReports.Engine.TextObject str_baocaongay;
                        str_baocaongay = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_tungaydenngay"];
                        str_baocaongay.Text = Variable.str_tungay;           //txt_ngaythangnam


                        CrystalDecisions.CrystalReports.Engine.TextObject str_ngayinbill;
                        str_ngayinbill = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_ngaythangnam"];
                        str_ngayinbill.Text = rm.GetString("ngay", culture) + " " + string.Format("{0:dd/MM/yyyy}", DateTime.Today);           //txt_ngaythangnam
                        //-------------------------------------------------------------
                        CrystalDecisions.CrystalReports.Engine.TextObject str_ban;
                        str_ban = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["Text2"];
                        str_ban.Text = rm.GetString("stt_bill", culture);
                        str_ban = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["Text1"];
                        str_ban.Text = rm.GetString("mon", culture);
                        str_ban = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["Text3"];
                        str_ban.Text = rm.GetString("soluong_bill", culture);
                        str_ban = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["Text4"];
                        str_ban.Text = rm.GetString("thanhtien_bill", culture);
                        str_ban = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["Text6"];
                        str_ban.Text = rm.GetString("tienmat_bill", culture);

                                                
                        rpt.SetDataSource(_dsbaocao.Tables[1]);
                        if(loaibaocao=="ban")
                            rpt.DataDefinition.FormulaFields["TIEUDE"].Text = "'BÁO CÁO DOANH THU BÀN'";
                        else
                            rpt.DataDefinition.FormulaFields["TIEUDE"].Text = "'BÁO CÁO DOANH THU KHU VỰC'";
                        rpt.DataDefinition.FormulaFields["HANGHOA"].Text = "{dt_report.HANGHOA}" + "";
                        rpt.DataDefinition.FormulaFields["SOLUONG"].Text = "{dt_report.SOLUONG}" + "";
                        rpt.DataDefinition.FormulaFields["THANHTIEN"].Text = "{dt_report.THANHTIENTRUOC}" + "";
                        //  rpt.DataDefinition.FormulaFields["CHENHLECH"].Text = "{dt_report.CHENHLECH}" + "";
                        rpt.DataDefinition.FormulaFields["TIENMAT"].Text = "{dt_report.TIENMAT}" + "";

                        #region "   PrinterDefault"
                        System.Drawing.Printing.PrinterSettings cls = new System.Drawing.Printing.PrinterSettings();
                        string sPrinterDefault = cls.PrinterName;
                        rpt.PrintOptions.PrinterName = sPrinterDefault;
                        #endregion
                        rpt.PrintToPrinter(1, true, 1, 100);

                        try
                        {
                            if (ocpublic.Registry_Get("chkCrystalReport_Display") + "" == "True")
                            {
                                mh_View frm = new mh_View(rpt);
                                frm.Show();
                            }
                        }
                        catch (Exception ex)
                        {
                        }

                        rpt.Dispose();//-----Xóa file tmp rpt---07/07/2012
                        #endregion
                    }
                    else
                    {
                        #region "bao cao may in ellic"

                        string mathang = "";
                        string thanhtien = "";
                        string chenhlech = "";
                        string tienmat = "";

                        foreach (SerialPort_LPV oSerialPort_LPV in aSerialPort_LPV)
                        {
                            if (oSerialPort_LPV != null)
                            {
                                //=======================================HEADER===============================================================================
                                oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Double_Height, "BAO CAO DOANH THU BAN", "", "", "");
                                oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, Variable.str_tungay, "", "", "");

                                oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, ' ', PrintCOMs.Fills.Fills_Full);

                                if (tencongty != "")
                                    oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, tencongty, "", "", "");
                                if (dienthoai != "")
                                    oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, dienthoai, "", "", "");
                                if (diachi != "")
                                    oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, diachi, "", "", "");

                                oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, '=', PrintCOMs.Fills.Fills_Full);
                                //==================================================DETAIL====================================================================
                                i1 = 20;
                                i2 = 10;
                                i3 = 11;   // = 56
                                oSerialPort_LPV.WriteLine(this.f_splitString4Column("Mat hang", "T tien", "Ch lech", "Tien mat", i1, i2, i3));

                                oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, '-', PrintCOMs.Fills.Fills_Full);

                                //========================================================
                                //lay dataset cua doanh thu theo nhom chu

                                tb = _dsbaocao.Tables[1];
                                for (int i = 0; i < tb.Rows.Count; i++)
                                {
                                    if (tb.Rows[i]["THANHTIENTRUOC"] + "" == "")
                                    {
                                        oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, '-', PrintCOMs.Fills.Fills_Full);
                                        continue;
                                    }

                                    ocpublic = new cpublic();
                                    mathang = ocpublic.RemoveSign4VietnameseString(tb.Rows[i]["HANGHOA"] + "");
                                    thanhtien = (decimal.Parse(tb.Rows[i]["THANHTIENTRUOC"] + "")).ToString("N0") + "";
                                    chenhlech = (decimal.Parse(tb.Rows[i]["CHENHLECH"] + "")).ToString("N0");
                                    tienmat = (decimal.Parse(tb.Rows[i]["TIENMAT"] + "")).ToString("N0");

                                    string mathang_2 = "";
                                    #region "   khuvuc_2"
                                    if (mathang.Length + thanhtien.Length >= i1)
                                    {
                                        int iSpace = 0;
                                        int icount = 0;
                                        while (icount + thanhtien.Length < i1)
                                        {
                                            if (mathang.IndexOf(' ', icount) == icount)
                                                iSpace = icount;
                                            icount++;
                                        }
                                        string sTmp = "";

                                        sTmp = mathang.Substring(0, iSpace).Trim();
                                        mathang_2 = mathang.Substring(iSpace).Trim();
                                        mathang = sTmp;

                                    }

                                    #endregion
                                    oSerialPort_LPV.WriteLine(this.f_splitString4Column(mathang, thanhtien, chenhlech, tienmat, i1, i2, i3));
                                    if (mathang_2 != "")
                                        oSerialPort_LPV.WriteLine(this.f_splitString4Column(mathang_2, "", "", "", i1, i2, i3));


                                    if (tb.Rows[i]["COLOR"] + "" == "2")
                                        oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, '-', PrintCOMs.Fills.Fills_Full);
                                }

                                //=======================================FOOTER===============================================================================
                                oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, '=', PrintCOMs.Fills.Fills_Full);
                                oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, "In bao cao ngay " + DateTime.Today.ToString("dd/MM/yyyy"), "", "", "");
                                oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, ' ', PrintCOMs.Fills.Fills_Full);

                                oPrintCOMs.Print_Bottom(oSerialPort_LPV);

                            }
                        }
                        #endregion
                    }
                }
                else
                {
                    Mod_messagebox mess = new Mod_messagebox();
                    mess.messagebox_pos("Thông báo", "Chưa có doanh thu", loaithongbao.canhbao.GetHashCode());
                    return;
                }

                break;
                #endregion
            case "kho":
                #region "   "
                if (_dsbaocao.Tables[0].Rows.Count > 0)
                {
                    //int vitri_bixolon_100 = dv.Find(new object[] { "BIXOLON100" });
                    if (vitri > -1 || vitri_bixolon > -1 || vitri_bixolon_100 > -1)
                    {
                        #region "bao cao ban tieng viet"

                        //bc_khohang_in_VN rpt = new bc_khohang_in_VN();
                        if (vitri > -1)
                            rpt = new bc_khohang_in_VN();
                        else
                            rpt = new bc_khohang_in_Bixolon();
                        //   bc_khohang_in_Bixolon rpt = new bc_khohang_in_Bixolon();


                        CrystalDecisions.CrystalReports.Engine.TextObject str_tencongty;
                        str_tencongty = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_tencongty"];
                        str_tencongty.Text = tencongty;

                        CrystalDecisions.CrystalReports.Engine.TextObject str_dienthoai;
                        str_dienthoai = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_dienthoaicongty"];
                        str_dienthoai.Text = dienthoai;

                        CrystalDecisions.CrystalReports.Engine.TextObject str_diachi;
                        str_diachi = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_diachicongty"];
                        str_diachi.Text = diachi;           //txt_ngaythangnam

                        CrystalDecisions.CrystalReports.Engine.TextObject str_baocaongay;
                        str_baocaongay = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_tungaydenngay"];
                        str_baocaongay.Text = Variable.str_tungay;           //txt_ngaythangnam
                        // ----------------------------------------------------------------
                        CrystalDecisions.CrystalReports.Engine.TextObject str_kho;
                        str_kho = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["Text3"];
                        str_kho.Text = rm.GetString("mon", culture);
                        str_kho = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["Text4"];
                        str_kho.Text = rm.GetString("dautien", culture);
                        str_kho = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["Text5"];
                        str_kho.Text = rm.GetString("nhap", culture);
                        str_kho = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["Text6"];
                        str_kho.Text = rm.GetString("xuat", culture);
                        str_kho = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["Text1"];
                        str_kho.Text = rm.GetString("ban_sal", culture);
                        str_kho = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["Text8"];
                        str_kho.Text = rm.GetString("cuoicung", culture);
                        

                        CrystalDecisions.CrystalReports.Engine.TextObject str_ngayinbill;
                        str_ngayinbill = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_ngaythangnam"];
                        str_ngayinbill.Text = rm.GetString("ngay", culture) + " " + string.Format("{0:dd/MM/yyyy}", DateTime.Today);           //txt_ngaythangnam
                        //anhlq
                        DataView dv1 = _dsbaocao.Tables[0].Copy().DefaultView;
                        dv1.RowFilter = @"TON_KHO_BAN_DAU <>0 
                                            OR NHAP_KHO<>0 
                                            OR XUAT_KHO<>0 
                                            OR NHAP_TRA_LAI<>0 
                                            OR BAN_RA<>0 
                                            OR BAN_RA<>0 
                                            OR TON_CUOI_KY <>0 
                                            OR LUONG_HANG_HOA_THAY_DOI<>0";

                       // rpt.SetDataSource(_dsbaocao.Tables[0]);
                        rpt.SetDataSource(dv1.ToTable());
                        //
                        rpt.DataDefinition.FormulaFields["SAN_PHAM"].Text = "{dt_report.SAN_PHAM}" + "";
                        rpt.DataDefinition.FormulaFields["TON_KHO_BAN_DAU"].Text = "{dt_report.TON_KHO_BAN_DAU}" + "";
                        rpt.DataDefinition.FormulaFields["NHAP_KHO"].Text = "{dt_report.NHAP_KHO}" + "";
                        rpt.DataDefinition.FormulaFields["XUAT_KHO"].Text = "{dt_report.XUAT_KHO}" + "";
                        rpt.DataDefinition.FormulaFields["BAN_RA"].Text = "{dt_report.BAN_RA}" + "";
                        rpt.DataDefinition.FormulaFields["TON_CUOI_KY"].Text = "{dt_report.TON_CUOI_KY}" + "";

                        #region "   PrinterDefault"
                        System.Drawing.Printing.PrinterSettings cls = new System.Drawing.Printing.PrinterSettings();
                        string sPrinterDefault = cls.PrinterName;
                        rpt.PrintOptions.PrinterName = sPrinterDefault;
                        #endregion
                        try
                        {
                            if (ocpublic.Registry_Get("chkCrystalReport_Display") + "" == "True")
                            {
                                mh_View frm = new mh_View(rpt);
                                frm.Show();
                            }
                        }
                        catch (Exception ex)
                        {
                        }
                        rpt.PrintToPrinter(1, true, 1, 100);
                        rpt.Dispose();//-----Xóa file tmp rpt---07/07/2012
                        #endregion
                    }
                    else
                    {
                        #region "bao cao may in ellic"
                        ocpublic = new cpublic();
                        string tonkhobandau = "";
                        string nhapkho = "";
                        string xuatkho = "";
                        string nhaptralai = "";
                        string banra = "";
                        string toncuoiky = "";
                        string luongbanhangthaydoi = "";

                        i1 = 22;
                        i2 = 8;
                        i3 = 12;   // = 56

                        foreach (SerialPort_LPV oSerialPort_LPV in aSerialPort_LPV)
                        {
                            if (oSerialPort_LPV != null)
                            {
                                string mathang = "";
                                //=======================================HEADER===============================================================================
                                oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Double_Height, "BAO CAO KHO", "", "", "");
                                oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, Variable.str_tungay, "", "", "");

                                oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, ' ', PrintCOMs.Fills.Fills_Full);

                                if (tencongty != "")
                                    oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, tencongty, "", "", "");
                                if (dienthoai != "")
                                    oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, dienthoai, "", "", "");
                                if (diachi != "")
                                    oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, diachi, "", "", "");

                                oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, '=', PrintCOMs.Fills.Fills_Full);

                                //lay dataset cua doanh thu theo nhom chu
                                tb = _dsbaocao.Tables[0];

                                int idem = 0;
                                for (int i = 0; i < tb.Rows.Count; i++)
                                {
                                    if (idem++ == 20)
                                    {
                                        idem = 0;
                                        for (int io = 0; io < 1000000000; io++)
                                            io = io + 0;
                                    }
                                    if (tb.Rows[i]["SAN_PHAM"] + "" == "" && i != tb.Rows.Count - 1)
                                    {
                                        oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, '-', PrintCOMs.Fills.Fills_Full);
                                        continue;// break;
                                    }
                                    mathang = ocpublic.RemoveSign4VietnameseString(tb.Rows[i]["SAN_PHAM"] + "");
                                    if (mathang != "")
                                    {
                                        tonkhobandau = decimal.Parse(string.Concat("0", tb.Rows[i]["TON_KHO_BAN_DAU"]).Replace("0-", "-")).ToString("N0");
                                        nhapkho = decimal.Parse(string.Concat("0", tb.Rows[i]["NHAP_KHO"]).Replace("0-", "-")).ToString("N0");
                                        xuatkho = decimal.Parse(string.Concat("0", tb.Rows[i]["XUAT_KHO"]).Replace("0-", "-")).ToString("N0");
                                        nhaptralai = decimal.Parse(string.Concat("0", tb.Rows[i]["NHAP_TRA_LAI"]).Replace("0-", "-")).ToString("N0");
                                        banra = decimal.Parse(string.Concat("0", tb.Rows[i]["BAN_RA"]).Replace("0-", "-")).ToString("N0");
                                        toncuoiky = decimal.Parse(string.Concat("0", tb.Rows[i]["TON_CUOI_KY"]).Replace("0-", "-")).ToString("N0");
                                        luongbanhangthaydoi = decimal.Parse(string.Concat("0", tb.Rows[i]["LUONG_HANG_HOA_THAY_DOI"]).Replace("0-", "-")).ToString("N0");

                                        oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, "[" + mathang + "]", "", "", "");
                                        oSerialPort_LPV.WriteLine(this.f_splitString2Column("Ton kho ban dau", tonkhobandau));
                                        oSerialPort_LPV.WriteLine(this.f_splitString2Column("Nhap kho", nhapkho));
                                        oSerialPort_LPV.WriteLine(this.f_splitString2Column("Xuat kho", xuatkho));
                                        oSerialPort_LPV.WriteLine(this.f_splitString2Column("Nhap tra lai", nhaptralai));
                                        oSerialPort_LPV.WriteLine(this.f_splitString2Column("Ban ra", banra));
                                        oSerialPort_LPV.WriteLine(this.f_splitString2Column("Ton cuoi ky", toncuoiky));
                                        oSerialPort_LPV.WriteLine(this.f_splitString2Column("Luong hang hoa thay doi", luongbanhangthaydoi));

                                        oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, '-', PrintCOMs.Fills.Fills_Full);
                                    }
                                }

                                //=======================================FOOTER===============================================================================
                                oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, '=', PrintCOMs.Fills.Fills_Full);
                                oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, "In bao cao ngay " + DateTime.Today.ToString("dd/MM/yyyy"), "", "", "");
                                oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, ' ', PrintCOMs.Fills.Fills_Full);

                                oPrintCOMs.Print_Bottom(oSerialPort_LPV);

                            }
                        }
                        #endregion
                    }
                }
                else
                {
                    Mod_messagebox mess = new Mod_messagebox();
                    mess.messagebox_pos("Thông báo", "Chưa có doanh thu", loaithongbao.canhbao.GetHashCode());
                    return;
                }
                break;
                #endregion
            case "kho_nhapxuat":
                #region "   "
                if (_dsbaocao.Tables[0].Rows.Count > 0)
                {
                    //int vitri_bixolon_100 = dv.Find(new object[] { "BIXOLON100" });
                    if (vitri > -1 || vitri_bixolon > -1 || vitri_bixolon_100 > -1)
                    {
                        #region "bao cao ban tieng viet"

                        // bc_khohang_nhapxuat_in_VN rpt = new bc_khohang_nhapxuat_in_VN();
                        if (vitri > -1)
                            rpt = new bc_khohang_nhapxuat_in_VN();
                        else
                            rpt = new bc_khohang_nhapxuat_in_Bixolon();
                        // bc_khohang_nhapxuat_in_Bixolon rpt = new bc_khohang_nhapxuat_in_Bixolon();

                        CrystalDecisions.CrystalReports.Engine.TextObject str_tencongty;
                        str_tencongty = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_tencongty"];
                        str_tencongty.Text = tencongty;

                        CrystalDecisions.CrystalReports.Engine.TextObject str_dienthoai;
                        str_dienthoai = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_dienthoaicongty"];
                        str_dienthoai.Text = dienthoai;

                        CrystalDecisions.CrystalReports.Engine.TextObject str_diachi;
                        str_diachi = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_diachicongty"];
                        str_diachi.Text = diachi;           //txt_ngaythangnam

                        CrystalDecisions.CrystalReports.Engine.TextObject str_baocaongay;
                        str_baocaongay = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_tungaydenngay"];
                        str_baocaongay.Text = Variable.str_tungay;           //txt_ngaythangnam
                        //-----------------------------------------------------------------
                        CrystalDecisions.CrystalReports.Engine.TextObject str_khonhapxuat;
                        str_khonhapxuat = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["Text1"];
                        str_khonhapxuat.Text = rm.GetString("stt_bill", culture);
                        str_khonhapxuat = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["Text2"];
                        str_khonhapxuat.Text = rm.GetString("mon", culture);
                        str_khonhapxuat = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["Text3"];
                        str_khonhapxuat.Text = rm.GetString("thaydoi", culture);
                        str_khonhapxuat = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["Text4"];
                        str_khonhapxuat.Text = rm.GetString("ngaygio", culture);
                        str_khonhapxuat = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["Text5"];
                        str_khonhapxuat.Text = rm.GetString("loai", culture);
                        str_khonhapxuat = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_baocaodoanhthu"];
                        str_khonhapxuat.Text = rm.GetString("bcnhapxuatctkho", culture);


                        CrystalDecisions.CrystalReports.Engine.TextObject str_ngayinbill;
                        str_ngayinbill = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_ngaythangnam"];
                        str_ngayinbill.Text = rm.GetString("ngay", culture) + " " + string.Format("{0:dd/MM/yyyy}", DateTime.Today);           //txt_ngaythangnam


                        rpt.SetDataSource(_dsbaocao.Tables[0]);
                        rpt.DataDefinition.FormulaFields["SAN_PHAM"].Text = "{dt_report.SAN_PHAM}" + "";
                        rpt.DataDefinition.FormulaFields["THAY_DOI"].Text = "{dt_report.THAY_DOI}" + "";
                        rpt.DataDefinition.FormulaFields["NGAY_GIO"].Text = "{dt_report.NGAY_GIO}" + "";
                        rpt.DataDefinition.FormulaFields["LOAI"].Text = "{dt_report.LOAI}" + "";

                        #region "   PrinterDefault"
                        System.Drawing.Printing.PrinterSettings cls = new System.Drawing.Printing.PrinterSettings();
                        string sPrinterDefault = cls.PrinterName;
                        rpt.PrintOptions.PrinterName = sPrinterDefault;
                        #endregion
                        try
                        {
                            if (ocpublic.Registry_Get("chkCrystalReport_Display") + "" == "True")
                            {
                                mh_View frm = new mh_View(rpt);
                                frm.Show();
                            }
                        }
                        catch (Exception ex)
                        {
                        }
                        rpt.PrintToPrinter(1, true, 1, 100);
                        rpt.Dispose();//-----Xóa file tmp rpt---07/07/2012
                        #endregion
                    }
                    else
                    {
                        #region "bao cao may in ellic"

                        i1 = 20;
                        i2 = 11;
                        i3 = 11;   // = 56
                        ocpublic = new cpublic();
                        foreach (SerialPort_LPV oSerialPort_LPV in aSerialPort_LPV)
                        {

                            if (oSerialPort_LPV != null)
                            {

                                string mathang = "";
                                string thaydoi = "";
                                string ngay = "";
                                string loai = "";

                                //2222
                                //=======================================HEADER===============================================================================
                                oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Double_Height, "BAO CAO KHO", "", "", "");
                                oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, Variable.str_tungay, "", "", "");

                                oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, ' ', PrintCOMs.Fills.Fills_Full);

                                if (tencongty != "")
                                    oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, tencongty, "", "", "");
                                if (dienthoai != "")
                                    oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, dienthoai, "", "", "");
                                if (diachi != "")
                                    oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, diachi, "", "", "");

                                oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, '=', PrintCOMs.Fills.Fills_Full);
                                //==================================================DETAIL====================================================================
                                oSerialPort_LPV.WriteLine(this.f_splitString4Column("San pham", "T doi", "Ngay", "Loai", i1, i2, i3));
                                oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, '-', PrintCOMs.Fills.Fills_Full);

                                //========================================================
                                //lay dataset cua doanh thu theo nhom chu


                                tb = _dsbaocao.Tables[0];
                                for (int i = 0; i < tb.Rows.Count; i++)
                                {

                                    ocpublic = new cpublic();
                                    mathang = ocpublic.RemoveSign4VietnameseString(tb.Rows[i]["SAN_PHAM"] + "");
                                    thaydoi = tb.Rows[i]["THAY_DOI"] + "  ";
                                    ngay = DateTime.Parse(tb.Rows[i]["NGAY_GIO"] + "").ToString("dd/MM/yyyy");
                                    loai = ocpublic.RemoveSign4VietnameseString(tb.Rows[i]["LOAI"] + "");

                                    string mathang_2 = "";
                                    #region "   nhomhang_2"
                                    if (mathang.Length + thaydoi.Length >= i1)
                                    {
                                        int iSpace = 0;
                                        int icount = 0;
                                        while (icount + thaydoi.Length < i1)
                                        {
                                            if (mathang.IndexOf(' ', icount) == icount)
                                                iSpace = icount;
                                            icount++;
                                        }
                                        string sTmp = "";

                                        sTmp = mathang.Substring(0, iSpace).Trim();
                                        mathang_2 = mathang.Substring(iSpace).Trim();
                                        mathang = sTmp;

                                    }

                                    #endregion

                                    oSerialPort_LPV.WriteLine(this.f_splitString4Column(mathang, thaydoi, ngay, loai, i1, i2, i3));
                                    if (mathang_2 != "")
                                        oSerialPort_LPV.WriteLine(this.f_splitString4Column(mathang_2, "", "", "", i1, i2, i3));


                                    //if (i != tb.Rows.Count - 1)
                                    //    oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, '-', PrintCOMs.Fills.Fills_Full);
                                }

                                //=======================================FOOTER===============================================================================
                                oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, '=', PrintCOMs.Fills.Fills_Full);
                                oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, "In bao cao ngay " + DateTime.Today.ToString("dd/MM/yyyy"), "", "", "");
                                oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, ' ', PrintCOMs.Fills.Fills_Full);

                                oPrintCOMs.Print_Bottom(oSerialPort_LPV);

                            }
                        }
                        #endregion
                    }
                }
                else
                {
                    Mod_messagebox mess = new Mod_messagebox();
                    mess.messagebox_pos("Thông báo", "Chưa có doanh thu", loaithongbao.canhbao.GetHashCode());
                    return;
                }
                break;

                #endregion
            case "khachhang_tongquat":
                #region "   "
                if (_dsbaocao.Tables[0].Rows.Count > 0)
                {
                    //int vitri_bixolon_100 = dv.Find(new object[] { "BIXOLON100" });
                    if (vitri > -1 || vitri_bixolon > -1 || vitri_bixolon_100 > -1)
                    {
                        #region "bao cao ban tieng viet"

                        // bc_khachhang_tongquat_in_VN rpt = new bc_khachhang_tongquat_in_VN();
                        if (vitri > -1)
                            rpt = new bc_khachhang_tongquat_in_VN();
                        else
                            rpt = new bc_khachhang_tongquat_in_Bixolon();
                        // bc_khachhang_tongquat_in_Bixolon rpt = new bc_khachhang_tongquat_in_Bixolon();

                        CrystalDecisions.CrystalReports.Engine.TextObject str_tencongty;
                        str_tencongty = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_tencongty"];
                        str_tencongty.Text = tencongty;

                        CrystalDecisions.CrystalReports.Engine.TextObject str_dienthoai;
                        str_dienthoai = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_dienthoaicongty"];
                        str_dienthoai.Text = dienthoai;

                        CrystalDecisions.CrystalReports.Engine.TextObject str_diachi;
                        str_diachi = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_diachicongty"];
                        str_diachi.Text = diachi;           //txt_ngaythangnam

                        CrystalDecisions.CrystalReports.Engine.TextObject str_baocaongay;
                        str_baocaongay = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_tungaydenngay"];
                        str_baocaongay.Text = Variable.str_tungay;           //txt_ngaythangnam

                        CrystalDecisions.CrystalReports.Engine.TextObject str_ngayinbill;
                        str_ngayinbill = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_ngaythangnam"];
                        str_ngayinbill.Text = rm.GetString("ngay", culture) + " " + string.Format("{0:dd/MM/yyyy}", DateTime.Today);           //txt_ngaythangnam
                        //-----------------------------------------------------------------
                        CrystalDecisions.CrystalReports.Engine.TextObject str_khachhangtongquat;
                        str_khachhangtongquat = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["Text1"];
                        str_khachhangtongquat.Text = rm.GetString("sotaikhoan", culture);
                        str_khachhangtongquat = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["Text2"];
                        str_khachhangtongquat.Text = rm.GetString("sobanhang", culture);
                        str_khachhangtongquat = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["Text3"];
                        str_khachhangtongquat.Text = rm.GetString("tongcong", culture);

                        str_khachhangtongquat = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_baocaodoanhthu"];
                        str_khachhangtongquat.Text = rm.GetString("bckhachhangtongquat", culture);




                        rpt.SetDataSource(_dsbaocao.Tables[0]);
                        rpt.DataDefinition.FormulaFields["SO_TAI_KHOAN"].Text = "{dt_report.SO_TAI_KHOAN}" + "";
                        rpt.DataDefinition.FormulaFields["SO_BAN_HANG"].Text = "{dt_report.SO_BAN_HANG}" + "";
                        rpt.DataDefinition.FormulaFields["TONG_CONG"].Text = "{dt_report.TONG_CONG}" + "";
                        rpt.DataDefinition.FormulaFields["LUOT_BAN_HANG_GAN_NHAT"].Text = "{dt_report.LUOT_BAN_HANG_GAN_NHAT}" + "";

                        #region "   PrinterDefault"
                        System.Drawing.Printing.PrinterSettings cls = new System.Drawing.Printing.PrinterSettings();
                        string sPrinterDefault = cls.PrinterName;
                        rpt.PrintOptions.PrinterName = sPrinterDefault;
                        #endregion
                        try
                        {
                            if (ocpublic.Registry_Get("chkCrystalReport_Display") + "" == "True")
                            {
                                mh_View frm = new mh_View(rpt);
                                frm.Show();
                            }
                        }
                        catch (Exception ex)
                        {
                        }
                        rpt.PrintToPrinter(1, true, 1, 100);
                        rpt.Dispose();//-----Xóa file tmp rpt---07/07/2012
                        #endregion
                    }
                    else
                    {
                        #region "bao cao may in ellic"
                        foreach (SerialPort_LPV oSerialPort_LPV in aSerialPort_LPV)
                        {
                            oSerialPort_LPV.Write(Print_Align_Left);
                            i1 = 20;
                            i2 = 11;
                            i3 = 11;
                            string mathe = "";
                            string sobanhang = "";
                            string tongcong = "";
                            string luotbanhanggannhat = "";

                            if (oSerialPort_LPV != null)
                            {
                                //=======================================HEADER===============================================================================
                                oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Double_Height, "BAO CAO KHACH HANG _ TONG QUAT", "", "", "");
                                oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, Variable.str_tungay, "", "", "");

                                oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, ' ', PrintCOMs.Fills.Fills_Full);

                                if (tencongty != "")
                                    oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, tencongty, "", "", "");
                                if (dienthoai != "")
                                    oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, dienthoai, "", "", "");
                                if (diachi != "")
                                    oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, diachi, "", "", "");

                                oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, '=', PrintCOMs.Fills.Fills_Full);
                                //==================================================DETAIL====================================================================
                                oSerialPort_LPV.WriteLine(this.f_splitString4Column("Ma the", "So bh", "T cong", "Luot bh gan nhat", i1, i2, i3));

                                oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, '-', PrintCOMs.Fills.Fills_Full);

                                //========================================================
                                //lay dataset cua doanh thu theo nhom chu

                                tb = _dsbaocao.Tables[0];
                                for (int i = 0; i < tb.Rows.Count; i++)
                                {

                                    mathe = tb.Rows[i]["SO_TAI_KHOAN"] + "";
                                    sobanhang = tb.Rows[i]["SO_BAN_HANG"] + "";
                                    tongcong = (decimal.Parse(tb.Rows[i]["TONG_CONG"] + "")).ToString("N0") + "";
                                    if (tb.Rows[i]["LUOT_BAN_HANG_GAN_NHAT"] + "" != "") 
                                    luotbanhanggannhat = ((DateTime)tb.Rows[i]["LUOT_BAN_HANG_GAN_NHAT"]).ToString("dd/MM/yyyy");

                                    oSerialPort_LPV.WriteLine(this.f_splitString4Column(mathe, sobanhang, tongcong, luotbanhanggannhat, i1, i2, i3));

                                }

                                //=======================================FOOTER===============================================================================
                                oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, '=', PrintCOMs.Fills.Fills_Full);
                                oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, "In bao cao ngay " + DateTime.Today.ToString("dd/MM/yyyy"), "", "", "");
                                oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, ' ', PrintCOMs.Fills.Fills_Full);

                                oPrintCOMs.Print_Bottom(oSerialPort_LPV);

                            }
                        }
                        #endregion
                    }
                }
                else
                {
                    Mod_messagebox mess = new Mod_messagebox();
                    mess.messagebox_pos("Thông báo", "Chưa có doanh thu", loaithongbao.canhbao.GetHashCode());
                    return;
                }
                break;
                #endregion
            case "khachhang_mathang":
                #region "   "
                if (_dsbaocao.Tables[0].Rows.Count > 0)
                {
                    //int vitri_bixolon_100 = dv.Find(new object[] { "BIXOLON100" });
                    if (vitri > -1 || vitri_bixolon > -1 || vitri_bixolon_100 > -1)
                    {
                        #region "bao cao ban tieng viet"

                        // bc_khachhang_chitietmathang_in_VN rpt = new bc_khachhang_chitietmathang_in_VN();
                        if (vitri > -1)
                            rpt = new bc_khachhang_chitietmathang_in_VN();
                        else
                            rpt = new bc_khachhang_chitietmathang_in_Bixolon();
                        // bc_khachhang_chitietmathang_in_Bixolon rpt = new bc_khachhang_chitietmathang_in_Bixolon();

                        CrystalDecisions.CrystalReports.Engine.TextObject str_tencongty;
                        str_tencongty = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_tencongty"];
                        str_tencongty.Text = tencongty;

                        CrystalDecisions.CrystalReports.Engine.TextObject str_dienthoai;
                        str_dienthoai = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_dienthoaicongty"];
                        str_dienthoai.Text = dienthoai;

                        CrystalDecisions.CrystalReports.Engine.TextObject str_diachi;
                        str_diachi = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_diachicongty"];
                        str_diachi.Text = diachi;           //txt_ngaythangnam

                        CrystalDecisions.CrystalReports.Engine.TextObject str_baocaongay;
                        str_baocaongay = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_tungaydenngay"];
                        str_baocaongay.Text = Variable.str_tungay;           //txt_ngaythangnam


                        CrystalDecisions.CrystalReports.Engine.TextObject str_ngayinbill;
                        str_ngayinbill = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_ngaythangnam"];
                        str_ngayinbill.Text = "In báo cáo ngày " + string.Format("{0:dd/MM/yyyy}", DateTime.Today);           //txt_ngaythangnam

                        rpt.SetDataSource(_dsbaocao.Tables[0]);
                        rpt.DataDefinition.FormulaFields["SAN_PHAM"].Text = "{dt_report.SAN_PHAM}" + "";
                        rpt.DataDefinition.FormulaFields["SL"].Text = "{dt_report.SL}" + "";
                        rpt.DataDefinition.FormulaFields["CONG"].Text = "{dt_report.CONG}" + "";
                        rpt.DataDefinition.FormulaFields["DC"].Text = "{dt_report.DC}" + "";
                        rpt.DataDefinition.FormulaFields["SALES"].Text = "{dt_report.SALES}" + "";

                        #region "   PrinterDefault"
                        System.Drawing.Printing.PrinterSettings cls = new System.Drawing.Printing.PrinterSettings();
                        string sPrinterDefault = cls.PrinterName;
                        rpt.PrintOptions.PrinterName = sPrinterDefault;
                        #endregion
                        try
                        {
                            if (ocpublic.Registry_Get("chkCrystalReport_Display") + "" == "True")
                            {
                                mh_View frm = new mh_View(rpt);
                                frm.Show();
                            }
                        }
                        catch (Exception ex)
                        {
                        }
                        rpt.PrintToPrinter(1, true, 1, 100);
                        rpt.Dispose();//-----Xóa file tmp rpt---07/07/2012
                        #endregion
                    }
                    else
                    {
                        #region "bao cao may in ellic"

                        foreach (SerialPort_LPV oSerialPort_LPV in aSerialPort_LPV)
                        {
                            if (oSerialPort_LPV != null)
                            {
                                ocpublic = new cpublic();
                                oSerialPort_LPV.Write(Print_Align_Left);
                                i1 = 20;
                                i2 = 12;
                                i3 = 10;
                                string mathang = "";
                                string cong = "";
                                string giamgia = "";
                                string banhang_kh = "";

                                //=======================================HEADER===============================================================================
                                oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Double_Height, "BAO CAO KHACH HANG _ MAT HANG", "", "", "");
                                oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, Variable.str_tungay, "", "", "");

                                oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, ' ', PrintCOMs.Fills.Fills_Full);

                                if (tencongty != "")
                                    oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, tencongty, "", "", "");
                                if (dienthoai != "")
                                    oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, dienthoai, "", "", "");
                                if (diachi != "")
                                    oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, diachi, "", "", "");

                                oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, '=', PrintCOMs.Fills.Fills_Full);
                                //==================================================DETAIL====================================================================
                                oSerialPort_LPV.WriteLine(this.f_splitString4Column("Mat hang", "Cong", "Giam gia", "Ban hang", i1, i2, i3));

                                oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, '-', PrintCOMs.Fills.Fills_Full);

                                //========================================================
                                //lay dataset cua doanh thu theo nhom chu

                                tb = _dsbaocao.Tables[0];
                                for (int i = 0; i < tb.Rows.Count; i++)
                                {
                                    if (tb.Rows[i]["SAN_PHAM"] + "" == "")
                                    {
                                        oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, '-', PrintCOMs.Fills.Fills_Full);
                                        continue;
                                    }

                                    mathang = ocpublic.RemoveSign4VietnameseString(tb.Rows[i]["SAN_PHAM"] + "");
                                    cong = (decimal.Parse(tb.Rows[i]["CONG"] + "")).ToString("N0");
                                    giamgia = (decimal.Parse(tb.Rows[i]["DC"] + "")).ToString("N0");
                                    banhang_kh = (decimal.Parse(tb.Rows[i]["SALES"] + "")).ToString("N0");

                                    string mathang_2 = "";
                                    #region "   nhomhang_2"
                                    if (mathang.Length + cong.Length >= i1)
                                    {
                                        int iSpace = 0;
                                        int icount = 0;
                                        while (icount + cong.Length < i1)
                                        {
                                            if (mathang.IndexOf(' ', icount) == icount)
                                                iSpace = icount;
                                            icount++;
                                        }
                                        string sTmp = "";

                                        sTmp = mathang.Substring(0, iSpace).Trim();
                                        mathang_2 = mathang.Substring(iSpace).Trim();
                                        mathang = sTmp;

                                    }

                                    #endregion

                                    oSerialPort_LPV.WriteLine(this.f_splitString4Column(mathang, cong, giamgia, banhang_kh, i1, i2, i3));
                                    if (mathang_2 != "")
                                        oSerialPort_LPV.WriteLine(this.f_splitString4Column(mathang_2, "", "", "", i1, i2, i3));

                                }

                                //=======================================FOOTER===============================================================================
                                oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, '=', PrintCOMs.Fills.Fills_Full);
                                oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, "In bao cao ngay " + DateTime.Today.ToString("dd/MM/yyyy"), "", "", "");
                                oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, ' ', PrintCOMs.Fills.Fills_Full);

                                oPrintCOMs.Print_Bottom(oSerialPort_LPV);

                            }
                        }
                        #endregion

                    }
                }
                else
                {
                    Mod_messagebox mess = new Mod_messagebox();
                    mess.messagebox_pos("Thông báo", "Chưa có doanh thu", loaithongbao.canhbao.GetHashCode());
                    return;
                }
                break;
                #endregion
            case "khachhang _ chitietso":
                #region "   "
                if (_dsbaocao.Tables[0].Rows.Count > 0)
                {

                    //int vitri_bixolon_100 = dv.Find(new object[] { "BIXOLON100" });
                    if (vitri > -1 || vitri_bixolon > -1 || vitri_bixolon_100 > -1)
                    {
                        #region "bao cao ban tieng viet"

                        //bc_khachhang_chitietso_in_VN rpt = new bc_khachhang_chitietso_in_VN();
                        if (vitri > -1)
                            rpt = new bc_khachhang_chitietso_in_VN();
                        else
                            rpt = new bc_khachhang_chitietso_in_Bixolon();
                        // bc_khachhang_chitietso_in_Bixolon rpt = new bc_khachhang_chitietso_in_Bixolon();

                        CrystalDecisions.CrystalReports.Engine.TextObject str_tencongty;
                        str_tencongty = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_tencongty"];
                        str_tencongty.Text = tencongty;

                        CrystalDecisions.CrystalReports.Engine.TextObject str_dienthoai;
                        str_dienthoai = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_dienthoaicongty"];
                        str_dienthoai.Text = dienthoai;

                        CrystalDecisions.CrystalReports.Engine.TextObject str_diachi;
                        str_diachi = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_diachicongty"];
                        str_diachi.Text = diachi;           //txt_ngaythangnam

                        CrystalDecisions.CrystalReports.Engine.TextObject str_baocaongay;
                        str_baocaongay = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_tungaydenngay"];
                        str_baocaongay.Text = Variable.str_tungay;           //txt_ngaythangnam


                        CrystalDecisions.CrystalReports.Engine.TextObject str_ngayinbill;
                        str_ngayinbill = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_ngaythangnam"];
                        str_ngayinbill.Text = "In báo cáo ngày " + string.Format("{0:dd/MM/yyyy}", DateTime.Today);           //txt_ngaythangnam

                        rpt.SetDataSource(_dsbaocao.Tables[0]);
                        rpt.DataDefinition.FormulaFields["NGAY_HE_THONG"].Text = "{dt_report.NGAY_HE_THONG}" + "";
                        rpt.DataDefinition.FormulaFields["TONG_CONG"].Text = "{dt_report.TONG_CONG}" + "";
                        rpt.DataDefinition.FormulaFields["TIEN_MAT"].Text = "{dt_report.TIEN_MAT}" + "";
                        rpt.DataDefinition.FormulaFields["DC"].Text = "{dt_report.DC}" + "";

                        #region "   PrinterDefault"
                        System.Drawing.Printing.PrinterSettings cls = new System.Drawing.Printing.PrinterSettings();
                        string sPrinterDefault = cls.PrinterName;
                        rpt.PrintOptions.PrinterName = sPrinterDefault;
                        #endregion
                        try
                        {
                            if (ocpublic.Registry_Get("chkCrystalReport_Display") + "" == "True")
                            {
                                mh_View frm = new mh_View(rpt);
                                frm.Show();
                            }
                        }
                        catch (Exception ex)
                        {
                        }
                        rpt.PrintToPrinter(1, true, 1, 100);
                        rpt.Dispose();//-----Xóa file tmp rpt---07/07/2012
                        #endregion
                    }
                    else
                    {
                        #region "bao cao may in ellic"
                        foreach (SerialPort_LPV oSerialPort_LPV in aSerialPort_LPV)
                        {
                            if (oSerialPort_LPV != null)
                            {

                                oSerialPort_LPV.Write(Print_Align_Left);
                                i1 = 20;
                                i2 = 12;
                                i3 = 10;
                                string ngayhethong = "";
                                string tongcong = "";
                                string tienmat = "";
                                string giamgia = "";

                                //=======================================HEADER===============================================================================
                                oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Double_Height, "BAO CAO KHACH HANG _ CHI TIET SO", "", "", "");
                                oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, Variable.str_tungay, "", "", "");

                                oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, ' ', PrintCOMs.Fills.Fills_Full);

                                if (tencongty != "")
                                    oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, tencongty, "", "", "");
                                if (dienthoai != "")
                                    oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, dienthoai, "", "", "");
                                if (diachi != "")
                                    oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, diachi, "", "", "");

                                oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, '=', PrintCOMs.Fills.Fills_Full);
                                //==================================================DETAIL====================================================================
                                oSerialPort_LPV.WriteLine(this.f_splitString4Column("Ngay he thong", "Tong cong", "Giam gia", "Tien mat", i1, i2, i3));
                                oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, '-', PrintCOMs.Fills.Fills_Full);

                                //========================================================
                                //lay dataset cua doanh thu theo nhom chu

                                tb = _dsbaocao.Tables[0];
                                for (int i = 0; i < tb.Rows.Count; i++)
                                {

                                    ngayhethong = tb.Rows[i]["NGAY_HE_THONG"] + "";
                                    tongcong = (decimal.Parse(tb.Rows[i]["TONG_CONG"] + "")).ToString("N0") + "";
                                    tienmat = (decimal.Parse(tb.Rows[i]["TIEN_MAT"] + "")).ToString("N0") + "";
                                    giamgia = (decimal.Parse(tb.Rows[i]["DC"] + "")).ToString("N0");
                                    oSerialPort_LPV.WriteLine(this.f_splitString4Column(ngayhethong, tongcong, giamgia, tienmat, i1, i2, i3));

                                }

                                //=======================================FOOTER===============================================================================
                                oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, '=', PrintCOMs.Fills.Fills_Full);
                                oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, "In bao cao ngay " + DateTime.Today.ToString("dd/MM/yyyy"), "", "", "");
                                oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, ' ', PrintCOMs.Fills.Fills_Full);

                                oPrintCOMs.Print_Bottom(oSerialPort_LPV);

                            }
                        }
                        #endregion
                    }
                }
                else
                {
                    Mod_messagebox mess = new Mod_messagebox();
                    mess.messagebox_pos("Thông báo", "Chưa có doanh thu", loaithongbao.canhbao.GetHashCode());
                    return;
                }
                break;
                #endregion
            case "Chi tiet phieu":
                #region "   "
                if (_dsbaocao.Tables[0].Rows.Count > 0)
                {
                    //int vitri_bixolon_100 = dv.Find(new object[] { "BIXOLON100" });
                    if (vitri > -1 || vitri_bixolon > -1 || vitri_bixolon_100 > -1)
                    {
                        #region "bao cao ban tieng viet"

                        //cb_nhanvien_phieu_in_VN rpt = new cb_nhanvien_phieu_in_VN();
                        if (vitri > -1)
                            rpt = new cb_nhanvien_phieu_in_VN();
                        else
                            rpt = new cb_nhanvien_phieu_in_Bixolon();

                        CrystalDecisions.CrystalReports.Engine.TextObject str_tencongty;
                        str_tencongty = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_tencongty"];
                        str_tencongty.Text = tencongty;

                        CrystalDecisions.CrystalReports.Engine.TextObject str_dienthoai;
                        str_dienthoai = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_dienthoaicongty"];
                        str_dienthoai.Text = dienthoai;

                        CrystalDecisions.CrystalReports.Engine.TextObject str_diachi;
                        str_diachi = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_diachicongty"];
                        str_diachi.Text = diachi;           //txt_ngaythangnam

                        CrystalDecisions.CrystalReports.Engine.TextObject str_baocaongay;
                        str_baocaongay = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_tungaydenngay"];
                        str_baocaongay.Text = Variable.str_tungay;           //txt_ngaythangnam

                        CrystalDecisions.CrystalReports.Engine.TextObject str_ngayinbill;
                        str_ngayinbill = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_ngaythangnam"];
                        str_ngayinbill.Text = "In báo cáo ngày " + string.Format("{0:dd/MM/yyyy}", DateTime.Today);           //txt_ngaythangnam

                        rpt.SetDataSource(_dsbaocao.Tables[0]);
                        rpt.DataDefinition.FormulaFields["SOPHIEU"].Text = "{dt_report.MAPHIEU}" + "";
                        rpt.DataDefinition.FormulaFields["DOANHTHU"].Text = "{dt_report.DOANHTHU}" + "";

                        #region "   PrinterDefault"
                        System.Drawing.Printing.PrinterSettings cls = new System.Drawing.Printing.PrinterSettings();
                        string sPrinterDefault = cls.PrinterName;
                        rpt.PrintOptions.PrinterName = sPrinterDefault;
                        #endregion
                        try
                        {
                            if (ocpublic.Registry_Get("chkCrystalReport_Display") + "" == "True")
                            {
                                mh_View frm = new mh_View(rpt);
                                frm.Show();
                            }
                        }
                        catch (Exception ex)
                        {
                        }
                        rpt.PrintToPrinter(1, true, 1, 100);
                        rpt.Dispose();//-----Xóa file tmp rpt---07/07/2012
                        #endregion
                    }
                    else
                    {
                        #region "bao cao may in ellic"

                        string sophieu = "";
                        decimal doanhthu = 0;

                        foreach (SerialPort_LPV oSerialPort_LPV in aSerialPort_LPV)
                        {
                            if (oSerialPort_LPV != null)
                            {
                                //=======================================HEADER===============================================================================
                                oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Double_Height, "BAO CAO DOANH NHAN VIEN THEO PHIEU", "", "", "");
                                oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, Variable.str_tungay, "", "", "");

                                oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, ' ', PrintCOMs.Fills.Fills_Full);

                                if (tencongty != "")
                                    oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, tencongty, "", "", "");
                                if (dienthoai != "")
                                    oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, dienthoai, "", "", "");
                                if (diachi != "")
                                    oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, diachi, "", "", "");

                                oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, '=', PrintCOMs.Fills.Fills_Full);
                                //==================================================DETAIL====================================================================
                                i1 = 20;
                                i2 = 10;
                                i3 = 12;   // = 56
                                oSerialPort_LPV.WriteLine(this.f_splitString4Column("STT", "So phieu", "", "Doanh thu", i1, i2, i3));

                                oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, '-', PrintCOMs.Fills.Fills_Full);

                                //========================================================
                                //lay dataset cua doanh thu theo nhom chu

                                tb = _dsbaocao.Tables[0];
                                for (int i = 0; i < tb.Rows.Count; i++)
                                {


                                    ocpublic = new cpublic();
                                    sophieu = ocpublic.RemoveSign4VietnameseString(tb.Rows[i]["MAPHIEU"] + "");
                                    //doanhthu = (decimal.Parse(tb.Rows[i]["DOANHTHU"] + "")).ToString("N0") + "";
                                    decimal.TryParse(tb.Rows[i]["DOANHTHU"] + "" + "", out doanhthu);




                                    oSerialPort_LPV.WriteLine(this.f_splitString4Column((i + 1).ToString(), sophieu, "", doanhthu.ToString("N0"), i1, i2, i3));
                                    //   oSerialPort_LPV.WriteLine(this.f_splitString4Column());


                                    if (tb.Rows[i]["COLOR"] + "" == "2")
                                        oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, '-', PrintCOMs.Fills.Fills_Full);
                                }

                                //=======================================FOOTER===============================================================================
                                oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, '=', PrintCOMs.Fills.Fills_Full);
                                oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, "In bao cao ngay " + DateTime.Today.ToString("dd/MM/yyyy"), "", "", "");
                                oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, ' ', PrintCOMs.Fills.Fills_Full);

                                oPrintCOMs.Print_Bottom(oSerialPort_LPV);

                            }
                        }
                        #endregion
                    }
                }
                else
                {
                    Mod_messagebox mess = new Mod_messagebox();
                    mess.messagebox_pos("Thông báo", "Chưa có doanh thu", loaithongbao.canhbao.GetHashCode());
                    return;
                }

                break;
                #endregion

            // bc httt, editor: PL, date: 2012.07.25
            case "thethanhtoan":
                #region "   bc theo thẻ thanh toán, ---editor: PL, date: 2012.07.27"

                if (dt_bcthe.Rows.Count < 0)
                    return;

                if (dt_bcthe.Rows.Count > 0)
                {
                    if (vitri > -1 || vitri_bixolon > -1 || vitri_bixolon_100 > -1)
                    {

                        #region "bao cao ban tieng viet"
                        if (vitri > -1)
                            rpt = new bc_thethanhtoan_in_VN();

                        else
                            rpt = new bc_thethanhtoan_in_Bixolon();

                        CrystalDecisions.CrystalReports.Engine.TextObject str_tencongty;
                        str_tencongty = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_tencongty"];
                        str_tencongty.Text = tencongty;

                        CrystalDecisions.CrystalReports.Engine.TextObject str_dienthoai;
                        str_dienthoai = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_dienthoaicongty"];
                        str_dienthoai.Text = dienthoai;

                        CrystalDecisions.CrystalReports.Engine.TextObject str_diachi;
                        str_diachi = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_diachicongty"];
                        str_diachi.Text = diachi;           //txt_ngaythangnam

                        CrystalDecisions.CrystalReports.Engine.TextObject str_baocaongay;
                        str_baocaongay = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_tungaydenngay"];
                        str_baocaongay.Text = Variable.str_tungay;           //txt_ngaythangnam


                        CrystalDecisions.CrystalReports.Engine.TextObject str_ngayinbill;
                        str_ngayinbill = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_ngaythangnam"];
                        str_ngayinbill.Text = rm.GetString("ngay", culture) + " " + string.Format("{0:dd/MM/yyyy}", DateTime.Today);           //txt_ngaythangnam
                        //-----------------------------------------------

                        CrystalDecisions.CrystalReports.Engine.TextObject str_bill;
                        str_bill = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["txt_baocaodoanhthu"];
                        str_bill.Text = rm.GetString("doanhthuthethanhtoan", culture);

                        str_bill = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["Text2"];
                        str_bill.Text = rm.GetString("stt_bill", culture);

                        str_bill = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["Text1"];
                        str_bill.Text = rm.GetString("loaithe", culture);

                        str_bill = (CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["Text3"];
                        str_bill.Text = rm.GetString("tienmat_bill", culture);

                        rpt.SetDataSource(dt_bcthe);
                        rpt.DataDefinition.FormulaFields["LOAITHE"].Text = "{dt_report.OBJNAME_CARD}" + "";
                        rpt.DataDefinition.FormulaFields["TONGTIEN"].Text = "{dt_report.TONGTIEN}" + "";


                        #region "   PrinterDefault"
                        System.Drawing.Printing.PrinterSettings cls = new System.Drawing.Printing.PrinterSettings();
                        string sPrinterDefault = cls.PrinterName;
                        if (sPrinterDefault != "")
                            rpt.PrintOptions.PrinterName = sPrinterDefault;


                        try
                        {
                            if (ocpublic.Registry_Get("chkCrystalReport_Display") + "" == "True")
                            {
                                mh_View frm = new mh_View(rpt);
                                frm.Show();
                            }
                        }
                        catch (Exception ex)
                        {
                        }
                        #endregion

                        rpt.PrintToPrinter(1, true, 1, 100);

                        #endregion

                    }
                    else
                    {
                        #region "bao cao may in ellic"

                        string loaithe = "";
                        ////string thanhtien = "";
                        string tienmat = "";
                        // string tyle = "";
                        foreach (SerialPort_LPV oSerialPort_LPV in aSerialPort_LPV)
                        {
                            if (oSerialPort_LPV != null)
                            {
                                //=======================================HEADER===============================================================================
                                oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Double_Height, "BAO CAO DOANH THU THE", "", "", "");
                                oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, Variable.str_tungay, "", "", "");

                                oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, ' ', PrintCOMs.Fills.Fills_Full);

                                if (tencongty != "")
                                    oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, tencongty, "", "", "");
                                if (dienthoai != "")
                                    oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, dienthoai, "", "", "");
                                if (diachi != "")
                                    oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, diachi, "", "", "");

                                oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, '=', PrintCOMs.Fills.Fills_Full);
                                //==================================================DETAIL====================================================================

                                oSerialPort_LPV.Write(Print_Align_Left);
                                i1 = 29;
                                i2 = 13;
                                //i3 = 10;   // = 56
                                //oSerialPort_LPV.WriteLine(this.f_splitString3Column("Nhom chu", "Thanh tien", "Tien mat", i1, i2));
                                oSerialPort_LPV.WriteLine(this.f_splitString2Column("Loai the", "Tien mat"));
                                oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, '-', PrintCOMs.Fills.Fills_Full);

                                //========================================================
                                //lay dataset cua doanh thu theo nhom chu

                                tb = dt_bcthe;
                                ocpublic = new cpublic();
                                for (int i = 0; i < tb.Rows.Count; i++)
                                {
                                    loaithe = ocpublic.RemoveSign4VietnameseString(tb.Rows[i]["OBJNAME_CARD"] + "");
                                    //thanhtien = (decimal.Parse(tb.Rows[i]["THANHTIENTRUOC"] + "")).ToString("N0");
                                    tienmat = (decimal.Parse(tb.Rows[i]["TONGTIEN"] + "")).ToString("N0");
                                    //tyle = tb.Rows[i]["TYLE"] + "";

                                    string loaithe_2 = "";
                                    #region "   loaithe_2"
                                    if (loaithe.Length >= i1)
                                    {
                                        int iSpace = 0;
                                        int icount = 0;
                                        while (icount < i1)
                                        {
                                            if (loaithe.IndexOf(' ', icount) == icount)
                                                iSpace = icount;
                                            icount++;
                                        }
                                        string sTmp = "";

                                        sTmp = loaithe.Substring(0, iSpace).Trim();
                                        loaithe_2 = loaithe.Substring(iSpace).Trim();
                                        loaithe = sTmp;

                                    }

                                    #endregion
                                    //oSerialPort_LPV.WriteLine(this.f_splitString3Column(nhomchu, '', tienmat, i1, i2));
                                    oSerialPort_LPV.WriteLine(this.f_splitString2Column(loaithe, tienmat));
                                    if (loaithe_2 != "")
                                        oSerialPort_LPV.WriteLine(this.f_splitString2Column(loaithe, tienmat));


                                    if (i != tb.Rows.Count - 1)
                                        oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, '-', PrintCOMs.Fills.Fills_Full);
                                }

                                //=======================================FOOTER===============================================================================
                                oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, '=', PrintCOMs.Fills.Fills_Full);
                                oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, "Ngày in bill " + DateTime.Today.ToString("dd/MM/yyyy"), "", "", "");
                                oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, ' ', PrintCOMs.Fills.Fills_Full);

                                oPrintCOMs.Print_Bottom(oSerialPort_LPV);

                            }
                        }
                        #endregion
                    }
                }
                else
                {
                    Mod_messagebox mess = new Mod_messagebox();
                    mess.messagebox_pos("Thông báo", "Chưa có doanh thu", loaithongbao.canhbao.GetHashCode());
                    return;
                }
                break;
                #endregion
        }
        
        oPrintCOMs.Print_Close();


    }
}
